Describe the bug
graphql-codegen --config codegen.yml
✔ Parse configuration
❯ Generate outputs
❯ Generate src/generated/graphql.ts
✔ Load GraphQL schemas
✖ Load GraphQL documents
→ Syntax Error: Unexpected Name "declare"
Generate
❯ Generate ./graphql.schema.json
✔ Load GraphQL schemas
✖ Load GraphQL documents
→ Syntax Error: Unexpected Name "declare"
Generate
Found 2 errors
✖ node_modules/graphql-toolkit/types/asyncro.d.graphql
Syntax Error: Unexpected Name "declare"
node_modules/graphql-toolkit/types/asyncro.d.graphql (1:1)
1: declare module 'asyncro' {
^
2: type AsyncFn<T> = () => PromiseLike<T>;
✖ node_modules/graphql-toolkit/types/asyncro.d.graphql
Syntax Error: Unexpected Name "declare"
node_modules/graphql-toolkit/types/asyncro.d.graphql (1:1)
1: declare module 'asyncro' {
^
2: type AsyncFn<T> = () => PromiseLike<T>;
To Reproduce
Steps to reproduce the behavior:
My GraphQL schema:
happens with any schema/service
My GraphQL operations:
happens with any operations
My codegen.yml config file:
overwrite: true
schema: "http://localhost:4000"
documents: "**/*.graphql"
generates:
src/generated/graphql.ts:
plugins:
- "typescript-react-apollo"
./graphql.schema.json:
plugins:
- "introspection"
Expected behavior
Successful script run.
Environment:
@graphql-codegen/...: Additional context
Have the same problem with v1.2.1, but v1.2.0 works
You are trying to parse a Typescript module definition as a GraphQL document.
Are you sure you really want to parse all .graphql files in node_modules? If not, you can either specify your .graphql files explicitly, put them in a subfolder and parse only that folder, or exclude node_modules with:
documents: "{,!(node_modules)/**/}*.graphql"
@pnordhus Thanks, that works (seeing a different error now though). This yml was given to me by the init function so I expected sensible defaults in an empty CRA app... 🤔
Same here—encountered the same issue also using a file generated by the wizard. Error didn’t make it clear it was a misconfiguration on my part
The init suggests to use **/*.graphql, but the default should be src/**/*.graphql to avoid including node_modules as default.
Updated it in: https://github.com/dotansimha/graphql-code-generator/pull/2012
Fixed in 1.3.0 🎉
Most helpful comment
You are trying to parse a Typescript module definition as a GraphQL document.
Are you sure you really want to parse all
.graphqlfiles innode_modules? If not, you can either specify your.graphqlfiles explicitly, put them in a subfolder and parse only that folder, or excludenode_moduleswith: