graphql-code-generator: More verbose error messages.
Is your feature request related to a problem? Please describe.
Currently it’s quite difficult to discern what exactly is going wrong if there’s an error. Error messages are simply along the lines of: An error has occurred in one of your documents.
Describe the solution you’d like I’d prefer the ability to either set a flag that makes it more verbose, or simply enable it by default to include the exact file and lines that are erroneous.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 24
- Comments: 35 (14 by maintainers)
Commits related to this issue
- Aggregate all GraphQLDocumentErrors and attach source file and position to each of them Related to https://github.com/dotansimha/graphql-code-generator/issues/925 — committed to ardatan/graphql-toolkit by DAB0mB 5 years ago
- Aggregate all GraphQLDocumentErrors and attach source file and position to each of them Related to https://github.com/dotansimha/graphql-code-generator/issues/925 — committed to ardatan/graphql-toolkit by DAB0mB 5 years ago
- Aggregate all GraphQLDocumentErrors and attach source file and position to each of them Related to https://github.com/dotansimha/graphql-code-generator/issues/925 — committed to ardatan/graphql-toolkit by DAB0mB 5 years ago
- Aggregate all GraphQLDocumentErrors and attach source file and position to each of them Related to https://github.com/dotansimha/graphql-code-generator/issues/925 — committed to ardatan/graphql-toolkit by DAB0mB 5 years ago
- Aggregate all GraphQLDocumentErrors and attach source file and position to each of them Related to https://github.com/dotansimha/graphql-code-generator/issues/925 — committed to ardatan/graphql-toolkit by DAB0mB 5 years ago
Good god please fix this. I love you guys but this makes be cry.
Thank you all and sorry for the inconvenience. @DAB0mB is working on a fix now 😃
I Have the same issue. I’ve tracked the problem to checkValidationErrors in graphql-toolkit
Problem is in
throw new Error("Found " + errorCount + " error" + (errorCount > 1 ? 's' : '') + " in your documents!");. The function collects the errors but does not pass them to the exception.This did the trick for me:
throw new Error("Found " + errorCount + " error" + (errorCount > 1 ? 's' : '') + " in your documents!" + errors.join());Fixed in 0.18.0 🎉
Setting
verbose:truein config file fixed this for meI wound up writing something like @williamluke4:
Running with e.g.
./node_modules/.bin/gql-gen |less, this will present errors like this:Hopefully this helps others get unstuck, but for graphql-code-generator we should figure out how to present errors nicely both with and without a TTY.
For now, a quick and easy way to get something in both scenarios is to catch the exception from graphql-toolkit’s
checkValidationErrors()and rethrow with more detail:We’ve encountered the same issue in our team and traced it down to a downstream change. codegen-cli makes use of the listr2 package to render the console output. Listr2 made in change beginning with v3.3.0 introducing the “formatOutput” render-parameter on its DefaultRenderer with the default option of “truncate”. This truncates any output that exceeds the current console width… 2 possible solutions here…
Cheers Alex
I’m adding tests to codegen and then we can release
I changed your code to be
console.log(JSON.stringify(errors));so that I could see the expanded error messages.Have the same problem.
“@graphql-codegen/cli”: “3.0.0”, “@graphql-codegen/typescript”: “3.0.0”, “@graphql-codegen/typescript-document-nodes”: “3.0.0”, “@graphql-codegen/typescript-operations”: “3.0.0”,
Windows 11, Node v18.1.0
output looks like this:
Not much info… “Solved” as described above, with adding console.log to \node_modules@graphql-codegen\core\cjs\codegen.js
@dotansimha update: we use
concurrentlypackage to rungql-genand a couple of other tasks in parallel. It’s not working with it, but a standalone command works fine.I’m on Windows - and the most I can get out of it is:
Found 2 errors in your documentsI can see that the validator throws aDetailedErrorwith actual detail - but I can’t get the console to actually log it. (unless I hack the source)@dotansimha I’m using bash
I’m having trouble with the download of a remote schema failing, and I don’t know exactly what it’s trying to download, nor do I know what the server is saying back. It’d be awesome if there was a --debug flag or something so I could see what it’s doing to help me troubleshoot.