You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using the @graphql-codegen/near-operation-file-preset to generate type definitions via the typescript plugin, the error messages when the query is invalid misses all relevent information to actually fix the problem.
Instead there are two different types of errors thrown:
when querying for fields that do not exist on all types of the union
TypeError: Cannot read properties of undefined (reading 'type')
at node_modules/@graphql-codegen/visitor-plugin-common/index.js:3038:65
when querying for an object that does not exist
lastType.getFields is not a function
Error: Unable to validate GraphQL document!
at node_modules/@graphql-codegen/near-operation-file-preset/index.js:206:19
query {
getABList {
id # this works as expected, since it is perfectly valid...onB {
fieldOnlyOnB
}
# throws "Cannot read properties of undefined (reading 'type')"fieldOnlyOnB # throws "lastType.getFields is not a function"invalidField { invalidSubField }
}
}
My codegen.yml config file:
schema: schema.graphqldocuments: document.graphqlgenerates:
types.ts:
# comment out the nexxt line and you will see proper error messagespreset: near-operation-filepresetConfig:
extension: .types.tsbaseTypesPath: "types.ts"plugins:
- typescript
Expected behavior
Proper, useful error mesages about errors in my query. The same as if I was not using the near-operation-file preset.
In the sandbox, just comment out the line preset: near-operation-file in codegen.yml and you will see the error messages that I expected.
Additional context
Obviously this is a very simplifyed reproduction case. Originally the problem occurred when we made a few changes to our API to use union types in certain situations.
When trying to run codegen afterwards, not having proper error messages made it very hard to update the client queries…
The text was updated successfully, but these errors were encountered:
Describe the bug
Original Issue: dotansimha/graphql-code-generator#7515
Describe the bug
When using the
@graphql-codegen/near-operation-file-preset
to generate type definitions via thetypescript
plugin, the error messages when the query is invalid misses all relevent information to actually fix the problem.Instead there are two different types of errors thrown:
when querying for fields that do not exist on all types of the union
when querying for an object that does not exist
To Reproduce
Steps to reproduce the behavior:
https://codesandbox.io/s/graphql-codegen-near-operation-file-error-5n915?file=/document.graphql
codegen.yml
config file:Expected behavior
Proper, useful error mesages about errors in my query. The same as if I was not using the
near-operation-file
preset.In the sandbox, just comment out the line
preset: near-operation-file
in codegen.yml and you will see the error messages that I expected.Environment:
@graphql-codegen/add
: ^3.1.1@graphql-codegen/cli
: ^2.4.0@graphql-codegen/near-operation-file-preset
: 2.2.4@graphql-codegen/typescript
: 2.4.3@graphql-codegen/typescript-operations
: 2.2.4graphql
: ^16.2.0Additional context
Obviously this is a very simplifyed reproduction case. Originally the problem occurred when we made a few changes to our API to use union types in certain situations.
When trying to run codegen afterwards, not having proper error messages made it very hard to update the client queries…
The text was updated successfully, but these errors were encountered: