-
Notifications
You must be signed in to change notification settings - Fork 1.4k
No error output whatsoever when parsed GraphQL documents have syntax errors #9172
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
Comments
I dug through the code and found there's already some infrastructure in place for this, https://github.com/ardatan/graphql-tools/blob/f66eae82b4dd561d750dcd7f419c6a6da7055550/packages/loaders/code-file/src/index.ts#L34-L37. You can enable it in your config like this: # graphql.config.yaml
schema: 'https://rickandmortyapi.com/graphql'
documents:
- 'src/**/*.{graphql,ts,tsx,js,jsx}'
extensions:
codegen:
noSilentErrors: true
# ^^^^^^^^^^^^^^^^^^^^-------- this option 🎉
overwrite: true
# silent: false
# debug: true
# verbose: true
# errorsOnly: false
ignoreNoDocuments: true
generates:
'src/graphql/':
preset: gql-tag-operations-preset
plugins:
- typescript-apollo-client-helpers
- fragment-matcher
config:
typesPrefix: I
enumPrefix: I
enumsAsTypes: true
documentVariableSuffix: Doc
fragmentVariableSuffix: Fragment
omitOperationSuffix: true # Don't add Query/Fragment/Subscription/Mutation suffix
dedupeFragments: true
exportFragmentSpreadSubTypes: true
nonOptionalTypename: true
flattenGeneratedTypes: false # Disabled since it removes fragment types |
Great find @bradleyayers! The JSDoc comment for the option states the following:
I wonder why this isn't the default behaviour? Maybe due to it being a breaking change? #3596 is the original PR that introduced this option. Perhaps the docs should be updated to recommend this setting 🤔 |
It is not the default behavior because we cannot assume all calls of |
You can get the filename by re-running with
My impression is that the root of the problem is the design of the loader chain, where if a loader throws an exception it skips to the next loader, until no loaders are left.
I don't fully understand this… could you give an example where the assumption doesn't hold? My sense is that most consumers would be entirely happy if every gql string literal must be a valid graphql document. |
graphql-codegen silently failing has been a bit of a challenge for me as well. I use the client preset and Any way for me to enable |
I just want to advocate for this being the default, or if not at least being encouraged in the docs. (Or at the very least mentioned in the docs). It's a huge violation of principle of least surprise for tools to have a syntax error in a gql document result in the entire file being silently ignored. This resulted in me wasting hours trying to figure out why a source file with gql queries wasn't being included. If it's too much of a breaking change to have generations start failing due to syntax errors, the default behavior could at least be to output a warning about the syntax error, and then change the optional config variable to something like |
I can reproduce this consistently when If you set it to I also can't get |
perhaps a happy middle ground here is to make the default behavior to log in the console which files are encountering errors, even if it doesn't break the build. silencing this log could be a opt-in config option. or at least logging which files are being skipped and why when VERBOSE is set to true. this github ticket being the only place where this behavior is documented is not a great developer experience. |
the docs don't need to recommend the setting as long as they reference it loudly. every developer is going to run into syntax issues from time to time that silently fail |
@dotansimha We are facing this issue as well and since we have bazelified the code generation, we aren't able to pass |
Hi all 👋 I've got an alpha version to fix some issues mentioned here and here:
There are a few improvements I'm making:
![]()
Note: |
Which packages are impacted by your issue?
@graphql-codegen/cli, @graphql-codegen/core, @graphql-codegen/gql-tag-operations-preset
Describe the bug
Likely related issues:
Running
graphql-codegen
in a project containing invalid GraphQL queries in typescript files wrapped withgql()
has some really strange and inconsistent behaviour with regards to error reporting:Running the
graphql-codegen
command with--debug
and/or--verbose
flags changes nothing, but prepending the command withDEBUG=1
does result in an error being logged in both cases, albeit with a bunch of noise surrounding it:DEBUG=1 graphql-codegen --verbose
outputYour Example Website or App
https://github.com/mogelbrod/graphql-codegen-issue
Steps to Reproduce the Bug or Issue
git clone https://github.com/mogelbrod/graphql-codegen-issue
cd graphql-codegen-issue
npm install
graphql-codegen
graphql-codegen
reports 1 error that this line/query has invalid GraphQL syntaxgraphql-codegen
reports 2 errors for invalid GraphQL syntax, one for each of the files. Each error output should also include the file path (and preferably line number) where the error occurred.Expected behavior
See
Expect:
in the "Steps to reproduce" list.Screenshots or Videos
No response
Platform
Codegen Config File
The text was updated successfully, but these errors were encountered: