graphql-code-generator: error: Syntax Error: Expected Name, found $
Describe the bug
when running the gql-gen tool on the schema.json file below I get the error: error: Syntax Error: Expected Name, found $ and nothing else, all other tools iv tried out does not give me any errors, so I am clueless on how to find the actual error here… a better error message could maybe help?
I have used GraphQL Playground and Apollo Engine to try and look for errors in the scema, but no luck…
To Reproduce Steps to reproduce the behavior:
- Use schema.json as Schema
- Run the following command:
gql-gen --schema schema.json --template graphql-codegen-typescript-template --out types.ts
Expected behavior
A types.ts file that compiles.
Environment:
- OS: Windows 10
- Codegen: 0.10.7
- Node: 10.0.0
DEBUG Output debug.log
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 23 (10 by maintainers)
@furier , If you do have GraphQL documents, you can try v0.12.4. Thanks to @jonaskello , now the error are printed in a better and readable way, and it’s pointing to the file with the errors.
@furier The change that was made was that each file is validated against the schema separately in order to be able to print which file caused which error.
Before all graphql from all files were concatenated into one big AST and then that was validated. This made it possible to find all fragments as they existed in the single AST, however it made it impossible to know which file caused which validation error. So we got some errors but no clue in which file it occured.
With the change we can trace all validation errors to files, however we cannot fully validate cases where a file imports a fragment from another file as that now will result in an unknown fragment error. This is because fragments are not resolved which I think they should be, but until then I think my quickfix would make it possible for you to run again.
Thank God (no I really mena you) for that fix, a lifesaver!
The line with the error seems to be
It is a generated query passed in to a gql tag at later stage like this
gql(query), I thought that the parser should only parse graphql within gql tags and not simple strings?@furier please try to use
0.12.5, it should show you the document/filename that caused this error.