@@ -543,3 +543,91 @@ test('subgraph ownership for external fields is correct', () => {
543543 'b' ,
544544 ] ) ;
545545} ) ;
546+
547+ test ( 'subgraph ownership picks first non external "join__field" annotation' , ( ) => {
548+ // See Product.weight within the schema
549+ // B is picked as the owner even though it is external
550+ const supergraphSdl = /* GraphQL */ `
551+ schema
552+ @link(url: "https://specs.apollo.dev/link/v1.0")
553+ @link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION) {
554+ query: Query
555+ }
556+
557+ directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
558+
559+ directive @join__graph(name: String!, url: String!) on ENUM_VALUE
560+
561+ directive @join__field(
562+ graph: join__Graph
563+ requires: join__FieldSet
564+ provides: join__FieldSet
565+ type: String
566+ external: Boolean
567+ override: String
568+ usedOverridden: Boolean
569+ ) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
570+
571+ directive @join__implements(
572+ graph: join__Graph!
573+ interface: String!
574+ ) repeatable on OBJECT | INTERFACE
575+
576+ directive @join__type(
577+ graph: join__Graph!
578+ key: join__FieldSet
579+ extension: Boolean! = false
580+ resolvable: Boolean! = true
581+ isInterfaceObject: Boolean! = false
582+ ) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
583+
584+ directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
585+
586+ scalar join__FieldSet
587+
588+ directive @link(
589+ url: String
590+ as: String
591+ for: link__Purpose
592+ import: [link__Import]
593+ ) repeatable on SCHEMA
594+
595+ scalar link__Import
596+
597+ enum link__Purpose {
598+ SECURITY
599+ EXECUTION
600+ }
601+
602+ enum join__Graph {
603+ A @join__graph(name: "a", url: "")
604+ B @join__graph(name: "b", url: "")
605+ }
606+
607+ type Product @join__type(graph: A, key: "id") @join__type(graph: B, key: "id") {
608+ id: ID!
609+ # THIS IS THE RELEVANT FIELD FOR THIS TEST
610+ weight: ProductWeight! @join__field(graph: B, external: true) @join__field(graph: A)
611+ shippingCosts: Int! @join__field(graph: B, requires: "weight{id}")
612+ }
613+
614+ type ProductWeight @join__type(graph: A) @join__type(graph: B) {
615+ id: ID! @join__field(graph: A) @join__field(graph: B, external: true)
616+ weight: Int! @join__field(graph: A)
617+ }
618+
619+ type Query @join__type(graph: A) @join__type(graph: B) {
620+ a: Product! @join__field(graph: A)
621+ g: ProductWeight! @join__field(graph: A)
622+ c: Product! @join__field(graph: B)
623+ }
624+ ` ;
625+
626+ const supergraphInfo = extractSuperGraphInformation ( parse ( supergraphSdl ! ) ) ;
627+ expect ( supergraphInfo . schemaCoordinateServicesMappings . get ( 'Product.weight' ) ) . toEqual ( [ 'a' ] ) ;
628+ expect ( supergraphInfo . schemaCoordinateServicesMappings . get ( 'ProductWeight.id' ) ) . toEqual ( [ 'a' ] ) ;
629+ expect ( supergraphInfo . schemaCoordinateServicesMappings . get ( 'ProductWeight' ) ) . toEqual ( [ 'a' , 'b' ] ) ;
630+ expect ( supergraphInfo . schemaCoordinateServicesMappings . get ( 'Product.shippingCosts' ) ) . toEqual ( [
631+ 'b' ,
632+ ] ) ;
633+ } ) ;
0 commit comments