Describe the bug
When I try to generate types from Gatsby schema, I get the following error
โ Parse configuration
โฏ Generate outputs
โฏ Generate ./src/types/generated/graphql.ts
โ Load GraphQL schemas
โ Load GraphQL documents
โ Identifier 'getIterator' has already been declared (3299:9)
Generate
Found 1 error
โ ./src/types/generated/graphql.ts
SyntaxError: Identifier 'getIterator' has already been declared (3299:9)
at Object._raise (/Users/smashercosmo/Documents/projects/gatsby-site/node_modules/@babel/parser/lib/index.js:766:17)
at Object.raiseWithData (/Users/smashercosmo/Documents/projects/gatsby-site/node_modules/@babel/parser/lib/index.js:
759:17)
at Object.raise (/Users/smashercosmo/Documents/projects/gatsby-site/node_modules/@babel/parser/lib/index.js:753:17)
at ScopeHandler.checkRedeclarationInScope (/Users/smashercosmo/Documents/projects/gatsby-site/node_modules/@babel/pa
rser/lib/index.js:4873:12)
at ScopeHandler.declareName (/Users/smashercosmo/Documents/projects/gatsby-site/node_modules/@babel/parser/lib/index
.js:4839:12)
To Reproduce
Steps to reproduce the behavior:
npm startnpm run graphql2tsEnvironment:
System:
OS: macOS 10.15.5
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.5.0 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.14.5 - /usr/local/bin/npm
Languages:
Python: 2.7.11 - /Library/Frameworks/Python.framework/Versions/2.7/bin/python
Browsers:
Chrome: 86.0.4240.183
Edge: 83.0.478.58
Firefox: 78.0.1
Safari: 13.1.1
npmPackages:
gatsby: 2.25.1
@graphql-codegen/cli: 1.19.0
@graphql-codegen/introspection: "1.18.0
@graphql-codegen/typescript: "1.17.11
@graphql-codegen/typescript-operations: 1.17.8
A temporary fix is to explicitly specify the Gatsby folders that have types, like so:
- node_modules/gatsby-transformer-sharp/!(node_modules)/**/*.js
So basically all the transformers?
Can confirm. Workaround works. Thx @femetrie
I'm closing for now.
Note that if you are using Gatsby, your schema and operations are spread across multiple packages, and codegen can't find those for your.
We always recommend to start with a narrow glob pattern, and extend it according to your needs. Using a broad pattern like ./node_modules/gatsby*/!(node_modules)/**/*.js will try to load a lot of files, and some might throw an error or create an incorrect schema.
@dotansimha thx for explanation, but have to mention that official Gatsby recipe recommends using a broad pattern
https://graphql-code-generator.com/docs/integrations/gatsby/
Got it, thanks @smashercosmo , I'll add a comment there to clarify this.
Maybe it's also great to give some advices which plugins usually need to be declared.
Hey, really feel this shouldn't be closed @dotansimha . My code previously worked and now is broken. Shouldn't you be leaving this open to come up with a more systematic Gatsby integration? If I'm not mistaken, Gatsby is one of the MAJOR frontend graphql implementations. This has already eaten up 2 days of coding time, I think I proly just need to find the duplicate getIterator thing myself, but there's really nothing helpful in the docs or on this thread currently. By closing the thread, you ensure that nothing else useful emerges. Hit you up on Discord, thx.
Pretty sure getIterator is declared in core-js: https://github.com/zloirock/core-js/search?q=getIterator
I think this issue may stem from multiple core-js versions. E.g. here's what I get when I run yarn why core-js:
```ยฑ |bg-lerna-swag {39} U:3 โ| โ yarn why core-js
yarn why v1.22.10
[1/4] ๐ค Why do we have the module "core-js"...?
[2/4] ๐ Initialising dependency graph...
[3/4] ๐ Finding dependency...
[4/4] ๐ก Calculating file sizes...
=> Found "[email protected]"
info Has been hoisted to "core-js"
info Reasons this module exists
Update: think I've got it working with this in the codegen.yml:
documents:
- ../glowystuff-web/src/**/*.{ts,tsx}
- ../../node_modules/gatsby-source-contentful/!(node_modules)/**/*.js
I think the issue was gatsby-recipes -> corejs, not sure though. Just wanna second the suggestion that people put in specific things they need.. but that this is a kind of variable step as it stands. Wonder if there's an approach that could avoid these issues with the Gatsby integration for future folks? All good though
I think it's the right way to advice the user to pick the specific documents, but as I mentioned before it would be great to have a more detailed explanation how to choose these paths.
Got it, @openscript, TBH, I'm not sure.
It really depends on what extensions you are using for Gatsby.
I'm not highly familiar with that, so unfortunately I can't recommend on the right way of doing that.
Most helpful comment
A temporary fix is to explicitly specify the Gatsby folders that have types, like so: