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

"Cannot read property 'name' of undefined" for invalid schema when skipDocumentsValidation: true #7252

Open
mogelbrod opened this issue Dec 21, 2021 · 0 comments
Labels
core Related to codegen core/cli kind/enhancement New feature or request

Comments

@mogelbrod
Copy link

mogelbrod commented Dec 21, 2021

Describe the bug

Running graphql-codegen configured with documents that refer to unknown query field(s) results in error(s) like the following:

AggregateError: GraphQL Document Validation failed with 1 errors;
      Error 0: GraphQLDocumentError: Cannot query field "undefinedField" on type "Query".

Re-running the CLI after enabling skipDocumentsValidation: true in the config instead results in:

TypeError: Cannot read property 'name' of undefined
    at .../node_modules/graphql/type/introspection.js:612:53
    at Array.some (<anonymous>)
    at Object.isIntrospectionType (.../node_modules/graphql/type/introspection.js:612:29)
    at Object.Field (.../node_modules/@graphql-codegen/typescript/index.js:390:25)
    at Object.enter (.../node_modules/graphql/utilities/TypeInfo.js:387:27)
    at Object.visit (.../node_modules/graphql/language/visitor.js:200:21)
    at .../node_modules/@graphql-codegen/typescript/index.js:395:38

To Reproduce

  1. Open codesandbox
  2. Allow graphql-codegen to run (restart container if necessary)
  3. Error is output in console

You can verify that it's caused by the querying of an unknown field by opening query.graphql, changing charactersX to characters and then re-running the CLI. This time it should succeed without any errors.

Expected behavior
No errors - the schema.ts file should be updated, but with types for the unknown query missing.

Environment:
See codesandbox

Additional context

Adding a guard against the undefined seems to be enough to avoid the error and allow the CLI to successfully generate otherwise working output, see this commit for a bare-bones fix: mogelbrod@99f9bd0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants