graphql-code-generator: Incorrect "Not all operations have an unique name" on 1.11.2
Describe the bug
1.11.2 is incorrectly stating “Not all operations have an unique name” when I attempt to run codegen; 1.8.3 was working fine.
To Reproduce
Codegen works fine on the Graphile Starter codegen-fine branch: https://github.com/graphile/starter/tree/codegen-fine
However, when we upgrade graphql-codegen from 1.8.3 to 1.11.2 we get the aforementioned error; see: https://github.com/graphile/starter/tree/codegen-bad which is one commit ahead of codegen-fine.
I’ve dug into this further; see “Additional context”
Running graphql-codegen results in:
✔ Parse configuration
❯ Generate outputs
❯ Generate index.tsx
✔ Load GraphQL schemas
✔ Load GraphQL documents
✖ Generate
→ Not all operations have an unique name: AddEmail
Found 1 error
✖ index.tsx
Not all operations have an unique name
* AddEmail found in:
- /home/benjie/Dev/starter/@app/client/src/graphql/AddEmail.graphql
- /home/benjie/Dev/starter/@app/client/src/graphql/DeleteEmail.graphql
- /home/benjie/Dev/starter/@app/client/src/graphql/EmailsForm_User.graphql
- /home/benjie/Dev/starter/@app/client/src/graphql/SettingsEmails.graphql
- /home/benjie/Dev/starter/@app/client/src/graphql/SettingsProfile.graphql
Error: Not all operations have an unique name: AddEmail
at validateDuplicateDocuments (/home/benjie/Dev/starter/node_modules/@graphql-codegen/core/index.cjs.js:200:1
5)
at Object.codegen (/home/benjie/Dev/starter/node_modules/@graphql-codegen/core/index.cjs.js:59:9)
at process (/home/benjie/Dev/starter/node_modules/@graphql-codegen/cli/bin.js:783:67)
at Array.map (<anonymous>)
at /home/benjie/Dev/starter/node_modules/@graphql-codegen/cli/bin.js:790:63
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Task.task (/home/benjie/Dev/starter/node_modules/@graphql-codegen/cli/bin.js:582:17)
Error: Not all operations have an unique name: AddEmail
at validateDuplicateDocuments (/home/benjie/Dev/starter/node_modules/@graphql-codegen/core/index.cjs.js:200:1
5)
at Object.codegen (/home/benjie/Dev/starter/node_modules/@graphql-codegen/core/index.cjs.js:59:9)
at process (/home/benjie/Dev/starter/node_modules/@graphql-codegen/cli/bin.js:783:67)
at Array.map (<anonymous>)
at /home/benjie/Dev/starter/node_modules/@graphql-codegen/cli/bin.js:790:63
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Task.task (/home/benjie/Dev/starter/node_modules/@graphql-codegen/cli/bin.js:582:17)
Expected behavior
Codegen should run as expected (since all my operations are uniquely named)
Environment:
- OS:
Ubuntu 18.04.3 LTS - NodeJS:
v12.13.1
"@graphql-codegen/add": "^1.11.2",
"@graphql-codegen/cli": "^1.11.2",
"@graphql-codegen/typescript": "^1.11.2",
"@graphql-codegen/typescript-operations": "^1.11.2",
"@graphql-codegen/typescript-react-apollo": "1.11.2"
Additional context
I investigated further using the Node debugger because this issue is bizarre. I ended up here:

Note that the rawSDL value for this entry has an import and mutation DeleteEmail; however the definitions entry contains an operation and a fragment, the operation is named AddEmail which is not sourced from this file. The imported fragment can be seen here but doesn’t contain any operations:
fragment EmailsForm_UserEmail on UserEmail {
id
email
isVerified
isPrimary
createdAt
}
Interestingly this fragment IS used by the AddEmail operation, so it looks like the re-used fragment is causing the file/operations to be interpretted incorrectly.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 32 (8 by maintainers)
Fixed in
v1.12.0🤷
It seems like latest version works, right? (
1.11.3-alpha-bb009c96.52) @will-hart @ardatan @benjie@ardatan Yep seems to have repaired the side effect on my end.
@benjie how did you manage to get such a detailed error message in your console? I only get:
I can’t figure out why it wont generate my DeleteGroup mutation and why it thinks the above two are have been made more than once.
how did you fix this in react?
My packages are:
@KillerCodeMonkey You should probably raise that as a separate issue 👍
Can confirm
1.11.3-alpha-bb009c96.52solves the issue in Graphile Starter; further it does not require theskipGraphQLImportflag (works both with and without that flag).Could you all try with the following version?
1.11.3-alpha-bb009c96.52