Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printSubgraphSchema fails if using a schema transformer and extending an external type #2865

Open
kal4l opened this issue Nov 22, 2023 · 0 comments

Comments

@kal4l
Copy link

kal4l commented Nov 22, 2023

Issue Description

If your subgraph has a schema that references an external type, e.g.

type SubgraphType {
  id: ID!
  external: ExternalType
}

extend type ExternalType @key(fields: "id") {
  id: ID! @external
}

and you have a transformer applied to the schema, e.g.

const schemaText = fs.readFileSync(path.join(__dirname, 'schema.graphql')).toString()
const typeDefs = gql(schemaText)

let schema = buildSubgraphSchema([
  { typeDefs }
])

schema = basicSchemaTransformer(schema)

Then printSubgraphSchema will fail with the error

GraphQLError: Type ExternalType must define one or more fields.
    at Object.err (/Users/kgrant/git/print-subgraph-schema-error/node_modules/@apollo/federation-internals/src/error.ts:36:60)
    at Validator.addError (/Users/kgrant/git/print-subgraph-schema-error/node_modules/@apollo/federation-internals/src/validate.ts:138:45)
    at Validator.validateObjectOrInterfaceType (/Users/kgrant/git/print-subgraph-schema-error/node_modules/@apollo/federation-internals/src/validate.ts:168:12)
    at Validator.validate (/Users/kgrant/git/print-subgraph-schema-error/node_modules/@apollo/federation-internals/src/validate.ts:90:16)
    at validateSchema (/Users/kgrant/git/print-subgraph-schema-error/node_modules/@apollo/federation-internals/src/validate.ts:30:32)
    at Schema.validate (/Users/kgrant/git/print-subgraph-schema-error/node_modules/@apollo/federation-internals/src/definitions.ts:1606:42)
    at Subgraph.validate (/Users/kgrant/git/print-subgraph-schema-error/node_modules/@apollo/federation-internals/src/federation.ts:1766:19)
    at buildSubgraph (/Users/kgrant/git/print-subgraph-schema-error/node_modules/@apollo/federation-internals/src/federation.ts:1329:19)
    at printSubgraphSchema (/Users/kgrant/git/print-subgraph-schema-error/node_modules/@apollo/subgraph/src/printSubgraphSchema.ts:16:33)
    at Object.<anonymous> (/Users/kgrant/git/print-subgraph-schema-error/src/print-schema.ts:4:32) {
  message: '[<unnamed>] Type ExternalType must define one or more fields.',
  path: undefined,
  locations: undefined,
  extensions: { code: 'INVALID_GRAPHQL' }
}

Link to Reproduction

https://github.com/kal4l/print-subgraph-schema-error

Reproduction Steps

  • See reproduction repo

Version

  • "@apollo/subgraph": "2.5.7"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant