import { buildSupergraphSchema , extractSubgraphsFromSupergraph } from ".." ; test ( 'handles types having no fields referenced by other objects in a subgraph correctly' , ( ) => { const supergraph = `
    schema
      @core(feature: "https://specs.apollo.dev/core/v0.2"),
      @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
    {
      query: Query
    }

    directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA

    directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION

    directive @join__graph(name: String!, url: String!) on ENUM_VALUE

    directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT

    directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT

    type A {
      a: B
    }

    type B {
      b: C @join__field(graph: SERVICEA, provides: \"c\")
    }

    type C {
      c: String
    }

    type D {
      d: String
    }

    type Query {
      q: A
    }

    enum core__Purpose {
      """
      \`EXECUTION\` features provide metadata necessary to for operation execution.
      """
      EXECUTION

      """
      \`SECURITY\` features provide metadata necessary to securely resolve fields.
      """
      SECURITY
    }

    scalar join__FieldSet

    enum join__Graph {
      SERVICEA @join__graph(name: "serviceA" url: "")
      SERVICEB @join__graph(name: "serviceB" url: "")
      SERVICEC @join__graph(name: "serviceC" url: "")
    }
  ` ; const schema = buildSupergraphSchema ( supergraph ) [ 0 ] ; const subgraphs = extractSubgraphsFromSupergraph ( schema ) ; expect ( subgraphs . size ( ) ) . toBe ( 3 ) ; const [ a , b , c ] = subgraphs . values ( ) . map ( ( s ) => s . schema ) ; expect ( a . type ( 'A' ) ) . toBeDefined ( ) ; expect ( a . type ( 'B' ) ) . toBeDefined ( ) ; expect ( b . type ( 'A' ) ) . toBeUndefined ( ) ; expect ( b . type ( 'B' ) ) . toBeUndefined ( ) ; expect ( c . type ( 'A' ) ) . toBeUndefined ( ) ; expect ( c . type ( 'B' ) ) . toBeUndefined ( ) ; } ) ; test ( 'handles types having no fields referenced by other interfaces in a subgraph correctly' , ( ) => { const supergraph = `
    schema
      @core(feature: "https://specs.apollo.dev/core/v0.2"),
      @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
    {
      query: Query
    }

    directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA

    directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION

    directive @join__graph(name: String!, url: String!) on ENUM_VALUE

    directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT

    directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT

    interface A {
      a: B
    }

    type B {
      b: C @join__field(graph: SERVICEA, provides: "c")
    }

    type C {
      c: String
    }

    type D {
      d: String
    }

    type Query {
      q: A
    }

    enum core__Purpose {
      """
      \`EXECUTION\` features provide metadata necessary to for operation execution.
      """
      EXECUTION

      """
      \`SECURITY\` features provide metadata necessary to securely resolve fields.
      """
      SECURITY
    }

    scalar join__FieldSet

    enum join__Graph {
      SERVICEA @join__graph(name: "serviceA" url: "")
      SERVICEB @join__graph(name: "serviceB" url: "")
      SERVICEC @join__graph(name: "serviceC" url: "")
    }
  ` ; const schema = buildSupergraphSchema ( supergraph ) [ 0 ] ; const subgraphs = extractSubgraphsFromSupergraph ( schema ) ; expect ( subgraphs . size ( ) ) . toBe ( 3 ) ; const [ a , b , c ] = subgraphs . values ( ) . map ( ( s ) => s . schema ) ; expect ( a . type ( 'A' ) ) . toBeDefined ( ) ; expect ( a . type ( 'B' ) ) . toBeDefined ( ) ; expect ( b . type ( 'A' ) ) . toBeUndefined ( ) ; expect ( b . type ( 'B' ) ) . toBeUndefined ( ) ; expect ( c . type ( 'A' ) ) . toBeUndefined ( ) ; expect ( c . type ( 'B' ) ) . toBeUndefined ( ) ; } ) ; test ( 'handles types having no fields referenced by other unions in a subgraph correctly' , ( ) => { const supergraph = `
    schema
      @core(feature: "https://specs.apollo.dev/core/v0.2"),
      @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
    {
      query: Query
    }

    directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA

    directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION

    directive @join__graph(name: String!, url: String!) on ENUM_VALUE

    directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT

    directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT

    union A = B | C

    type B {
      b: D @join__field(graph: SERVICEA, provides: "d")
    }

    type C {
      c: D @join__field(graph: SERVICEA, provides: "d")
    }

    type D {
      d: String
    }

    type Query {
      q: A
    }

    enum core__Purpose {
      """
      \`EXECUTION\` features provide metadata necessary to for operation execution.
      """
      EXECUTION

      """
      \`SECURITY\` features provide metadata necessary to securely resolve fields.
      """
      SECURITY
    }

    scalar join__FieldSet

    enum join__Graph {
      SERVICEA @join__graph(name: "serviceA" url: "")
      SERVICEB @join__graph(name: "serviceB" url: "")
    }
  ` ; const schema = buildSupergraphSchema ( supergraph ) [ 0 ] ; const subgraphs = extractSubgraphsFromSupergraph ( schema ) ; expect ( subgraphs . size ( ) ) . toBe ( 2 ) ; const [ a , b ] = subgraphs . values ( ) . map ( ( s ) => s . schema ) ; expect ( a . type ( 'A' ) ) . toBeDefined ( ) ; expect ( a . type ( 'B' ) ) . toBeDefined ( ) ; expect ( a . type ( 'C' ) ) . toBeDefined ( ) ; expect ( a . type ( 'D' ) ) . toBeDefined ( ) ; expect ( b . type ( 'A' ) ) . toBeUndefined ( ) ; expect ( b . type ( 'B' ) ) . toBeUndefined ( ) ; expect ( b . type ( 'C' ) ) . toBeUndefined ( ) ; expect ( a . type ( 'D' ) ) . toBeDefined ( ) ; } ) ; test ( 'handles types having only some of their fields removed in a subgraph correctly' , ( ) => { const supergraph = `
    schema
      @core(feature: "https://specs.apollo.dev/core/v0.2"),
      @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
    {
      query: Query
    }

    directive @core(as: String, feature: String!, for: core__Purpose) repeatable on SCHEMA

    directive @join__field(graph: join__Graph, provides: join__FieldSet, requires: join__FieldSet) on FIELD_DEFINITION

    directive @join__graph(name: String!, url: String!) on ENUM_VALUE

    directive @join__owner(graph: join__Graph!) on INTERFACE | OBJECT

    directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on INTERFACE | OBJECT

    type A {
      a: B
    }

    type B {
      b: C @join__field(graph: SERVICEA, provides: "c")
      c: Int
    }

    type C {
      c: String
    }

    type D {
      d: String
    }

    type Query {
      q: A
    }

    enum core__Purpose {
      """
      \`EXECUTION\` features provide metadata necessary to for operation execution.
      """
      EXECUTION

      """
      \`SECURITY\` features provide metadata necessary to securely resolve fields.
      """
      SECURITY
    }

    scalar join__FieldSet

    enum join__Graph {
      SERVICEA @join__graph(name: "serviceA" url: "")
      SERVICEB @join__graph(name: "serviceB" url: "")
      SERVICEC @join__graph(name: "serviceC" url: "")
    }
  ` ; const schema = buildSupergraphSchema ( supergraph ) [ 0 ] ; const subgraphs = extractSubgraphsFromSupergraph ( schema ) ; expect ( subgraphs . size ( ) ) . toBe ( 3 ) ; const [ a , b , c ] = subgraphs . values ( ) . map ( ( s ) => s . schema ) ; expect ( a . type ( 'A' ) ) . toBeDefined ( ) ; expect ( a . type ( 'B' ) ) . toBeDefined ( ) ; expect ( b . type ( 'A' ) ) . toBeDefined ( ) ; expect ( b . type ( 'B' ) ) . toBeDefined ( ) ; expect ( c . type ( 'A' ) ) . toBeDefined ( ) ; expect ( c . type ( 'B' ) ) . toBeDefined ( ) ; } ) ;