Describe the bug
After regenerating package-lock started getting this error
> graphql-codegen --config codegen.yml
✔ Parse configuration
❯ Generate outputs
❯ Generate ./src/types/generated/graphql.ts
✔ Load GraphQL schemas
✖ Load GraphQL documents
→ 'return' outside of function (13:4)
Generate
Found 1 error
✖ ./src/types/generated/graphql.ts
SyntaxError: 'return' outside of function (13:4)
at Object._raise (/Users/path-to-project/node_modules/@babel/parser/lib/index.js:742:17)
at Object.raiseWithData (/Users/path-to-project/node_modules/@babel/parser/lib/index.js:735:17)
To Reproduce
Steps to reproduce the behavior:
I'm using graphql-code-generator with Gatsby
overwrite: true
schema: "http://localhost:8000/___graphql"
documents:
- ./src/**/*.{ts,tsx}
- ./node_modules/gatsby-*/**/*.js
generates:
./src/types/generated/graphql.ts:
hooks:
afterOneFileWrite:
- prettier --write
plugins:
- typescript
- typescript-operations
config:
namingConvention:
enumValues: keep
avoidOptionals: true
immutableTypes: true
maybeValue: T
Environment:
System:
OS: macOS Mojave 10.14
CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
Shell: 5.3 - /bin/zsh
Binaries:
Node: 12.14.1 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Languages:
Python: 2.7.10 - /usr/bin/python
Browsers:
Chrome: 81.0.4044.113
Firefox: 72.0.2
Safari: 12.0
npmPackages:
gatsby: 2.20.23
@graphql-codegen/cli: 1.13.2
@graphql-codegen/introspection: 1.13.2
@graphql-codegen/typescript: 1.13.2
@graphql-codegen/typescript-operations: 1.13.2
Could you share a reproduction repo or CodeSandbox?
I'd love to, but not quite sure how to do it
l can try to run clean Gatsby project with latest gatsby and graphql-code-generator. Let's see if it results in error.
Reproduction https://github.com/smashercosmo/graphql-code-generator-issue
npm run developnpm run graphql2ts@smashercosmo ./src/**/*.{ts,tsx} is too wide so every single file is getting parsed to find a valid GraphQL operation, so I recommend you to narrow it down a little bit.
@ardatan I removed almost all the tsx files. But I think the error is caused by gatsby files.
If I remove this line https://github.com/smashercosmo/graphql-code-generator-issue/blob/master/codegen.yml#L5 error goes away
Ok, actually replacing this line with officially recommended
- ./node_modules/gatsby*/!(node_modules)/**/*.js fixes the issue.
So we can close the issue, right?
Yes, thx
Most helpful comment
Ok, actually replacing this line with officially recommended
- ./node_modules/gatsby*/!(node_modules)/**/*.jsfixes the issue.