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:
Ubuntu 18.04.3 LTSv12.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.
Same here. Version 1.9.1 works fine, in Version 1.10.0 I get following error in my project:
Error:
Import statement is not valid: import '../../fragments/Paginator.gql'
If you want to have comments starting with '# import', please use ''' instead!
You can only have 'import' statements in the following pattern;
# import [Type].[Field] from [File]
With 1.12.2 I get following error:
Not all operations have an unique name
* GetConsultancies found in:
- .../graphql/ressources/consultancies/GetConsultancies.gql
- .../graphql/ressources/consultancies/GetConsultancyForView.gql
- .../graphql/ressources/consultants/GetConsultantForView.gql
- .../graphql/ressources/consultants/GetConsultants.gql
- .../graphql/ressources/functionings/GetFunctionings.gql
- .../graphql/ressources/industries/GetIndustries.gql
- .../graphql/ressources/itSkills/GetItSkills.gql
- .../graphql/ressources/qualifications/GetQualifications.gql
And I named queries like the file names. Got to stay with Version 1.9.1 ATM
It should be somehow related to imports of fragments
Could you try the following?
schema: ...
documents:
- your-documents-pointer:
skipGraphQLImport: true
@ardatan I just found it in other issue. Tried it out, and for 1.11.2 it didn't help
here is my config:
overwrite: true
schema: "http://localhost/graphql"
documents:
- "./graphql/**/*.gql":
skipGraphQLImport: true
generates:
graphql/GQLTypes.ts:
plugins:
- typescript
- typescript-operations
config:
scalars:
ObfId: number
Json: "{ [key: string]: any }"
@ardatan Assuming I've got the YAML sigils in the correct places, this doesn't seem to have made any difference:

I get a similar issue with updating from 1.9.1 to 1.11.2 or 1.11.3-alpha-f3691f38.45
Found 1 error
GraphQLError: RelayParser: Encountered duplicate definitions for one or more documents: each document must have a unique name.
Duplicated documents:
- ((all the fragments defined in fragments.graphql))
at createUserError (\node_modules\relay-compiler\lib\core\CompilerError.js:31:10)
at new RelayParser (\node_modules\relay-compiler\lib\core\RelayParser.js:115:13)
at \node_modules\relay-compiler\lib\core\RelayParser.js:81:18
at Object.run (\node_modules\relay-compiler\lib\core\GraphQLCompilerProfiler.js:55:30)
at Object.transform (\node_modules\relay-compiler\lib\core\RelayParser.js:80:19)
at Object.optimizeOperations (\node_modules\@graphql-codegen\visitor-plugin-common\index.cjs.js:2223:49)
at executePlugin (\node_modules\@graphql-codegen\core\index.cjs.js:50:41)
at Promise.all.options.plugins.map (\node_modules\@graphql-codegen\core\index.cjs.js:106:30)
at Array.map (<anonymous>)
at Object.codegen (\node_modules\@graphql-codegen\core\index.cjs.js:96:54)
It appears to break on the fragments which are defined in a separate file. This is my config
overwrite: true
schema: "schema.gql"
documents:
- "path/to/packages/*.gql":
skipGraphQLImport: true
generates:
path/to/packages/generatedTypes.ts:
plugins:
- "typescript"
- "typescript-operations"
config:
namingConvention:
typeNames: change-case#pascalCase
enumValues: change-case#upperCase
preResolveTypes: true
flattenGeneratedTypes: true
skipTypename: true
declarationKind: 'interface'
typesPrefix: I
enumPrefix: false
path/to/packages/generatedOperations.ts:
plugins:
- "typescript-document-nodes"
config:
namingConvention:
typeNames: change-case#pascalCase
enumValues: change-case#upperCase
nameSuffix: "Document"
skipTypename: true
Edit: It builds if I delete the line that imports fragments.graphql (edit edit: but the typescript is invalid as the fragments are undefined)
Could you all try with the following version?
1.11.3-alpha-bb009c96.52
Just tried it - generated files are now correct. But I got other problem in my package...
These dependencies were not found: friendly-errors 00:47:30
friendly-errors 00:47:30
* core-js/modules/es6.array.find in ./.nuxt/client.js friendly-errors 00:47:30
* core-js/modules/es6.array.iterator in ./.nuxt/client.js friendly-errors 00:47:30
* core-js/modules/es6.date.to-string in ./.nuxt/utils.js, ./.nuxt/components/nuxt.js and 5 others friendly-errors 00:47:30
* core-js/modules/es6.function.name in ./.nuxt/client.js, ./node_modules/babel-loader/lib??ref--13-0!./node_modules/ts-loader??ref--13-1!./node_modules/vue-loader/lib??vue-loader-options!./components/admin/HistoryList.vue?vue&type=script&lang=ts& and 4 others
* core-js/modules/es6.number.constructor in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./node_modules/sweet-modal-vue/src/components/SweetModal.vue?vue&type=script&lang=js&, ./node_modules/babel-loader/lib??ref--13-0!./node_modules/ts-loader??ref--13-1!./node_modules/vue-loader/lib??vue-loader-options!./pages/admin/consultancies/_id/index.vue?vue&type=script&lang=ts& and 5 others
* core-js/modules/es6.number.parse-int in ./node_modules/babel-loader/lib??ref--13-0!./node_modules/ts-loader??ref--13-1!./node_modules/vue-loader/lib??vue-loader-options!./pages/admin/consultancies/_id/index.vue?vue&type=script&lang=ts&, ./node_modules/babel-loader/lib??ref--13-0!./node_modules/ts-loader??ref--13-1!./node_modules/vue-loader/lib??vue-loader-options!./pages/admin/consultants/_id/index.vue?vue&type=script&lang=ts& and 4 others
* core-js/modules/es6.object.assign in ./.nuxt/client.js friendly-errors 00:47:30
* core-js/modules/es6.object.keys in ./.nuxt/client.js, ./node_modules/babel-loader/lib??ref--13-0!./node_modules/ts-loader??ref--13-1!./node_modules/vue-loader/lib??vue-loader-options!./components/admin/HistoryList.vue?vue&type=script&lang=ts& and 4 others
* core-js/modules/es6.object.to-string in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 7 others friendly-errors 00:47:30
* core-js/modules/es6.promise in ./.nuxt/client.js friendly-errors 00:47:30
* core-js/modules/es6.regexp.constructor in ./.nuxt/utils.js friendly-errors 00:47:30
* core-js/modules/es6.regexp.match in ./.nuxt/client.js, ./node_modules/babel-loader/lib??ref--13-0!./node_modules/ts-loader??ref--13-1!./node_modules/vue-loader/lib??vue-loader-options!./components/globals/form/FInput.vue?vue&type=script&lang=ts&
* core-js/modules/es6.regexp.replace in ./.nuxt/utils.js, ./.nuxt/components/nuxt.js and 5 others friendly-errors 00:47:30
* core-js/modules/es6.regexp.search in ./.nuxt/utils.js, ./node_modules/babel-loader/lib??ref--13-0!./node_modules/ts-loader??ref--13-1!./node_modules/vue-loader/lib??vue-loader-options!./pages/admin/consultancies/index.vue?vue&type=script&lang=ts& and 5 others
* core-js/modules/es6.regexp.split in ./.nuxt/utils.js, ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./.nuxt/components/nuxt-build-indicator.vue?vue&type=script&lang=js& and 3 others
* core-js/modules/es6.regexp.to-string in ./.nuxt/utils.js, ./.nuxt/components/nuxt.js and 5 others friendly-errors 00:47:30
* core-js/modules/es6.string.includes in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 3 others friendly-errors 00:47:30
* core-js/modules/es6.string.iterator in ./.nuxt/client.js friendly-errors 00:47:30
* core-js/modules/es6.string.link in ./node_modules/babel-loader/lib??ref--13-0!./node_modules/ts-loader??ref--13-1!./node_modules/vue-loader/lib??vue-loader-options!./components/admin/LabeledValue.vue?vue&type=script&lang=ts& friendly-errors 00:47:30
* core-js/modules/es6.string.repeat in ./.nuxt/utils.js friendly-errors 00:47:30
* core-js/modules/es6.string.starts-with in ./.nuxt/utils.js friendly-errors 00:47:30
* core-js/modules/es6.symbol in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 4 others friendly-errors 00:47:30
* core-js/modules/es7.array.includes in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 3 others friendly-errors 00:47:30
* core-js/modules/es7.object.get-own-property-descriptors in ./.nuxt/index.js, ./node_modules/babel-loader/lib??ref--13-0!./node_modules/ts-loader??ref--13-1!./node_modules/vue-loader/lib??vue-loader-options!./components/admin/HistoryList.vue?vue&type=script&lang=ts& and 3 others
* core-js/modules/es7.object.values in ./helpers/validationHelpers.ts friendly-errors 00:47:30
* core-js/modules/es7.promise.finally in ./.nuxt/client.js friendly-errors 00:47:30
* core-js/modules/es7.symbol.async-iterator in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js friendly-errors 00:47:30
* core-js/modules/web.dom.iterable in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js and 5 others
Dunno how this is related to this project, but with 1.9.1 I don't receive this error
@benjie I see but as I asked in here;
https://github.com/dotansimha/graphql-code-generator/pull/3328#issuecomment-576479396
I need a clear minimal production to help your better. :)
1.11.3-alpha-bb009c96.52 resolves my error above :+1:
It seems like latest version works, right? (1.11.3-alpha-bb009c96.52) @will-hart @ardatan @benjie
@lorado it seems like an issue with nuxt/core-js, not sure it's related to the codegen...
Can confirm 1.11.3-alpha-bb009c96.52 solves the issue in Graphile Starter; further it does not require the skipGraphQLImport flag (works both with and without that flag).
@dotansimha Well yes, I understand, that my problem is somewhere in combination of nuxt and graphql-codegen. But the fact is, with 1.9.1 it works.
Just for the info: I dived a little bit deeper to find the error, and I found it. After comparison of yarn.lock I found out, that graphql-codegen has new @graphql-toolkit/apollo-engine-loader dependency, that has apollo-language-server dependency that has core-js "^3.0.1"dependency. And that is actually the problem, because I got new dependency: [email protected].
Nuxt uses babel, and therefore install [email protected]. In @nuxt/babel-preset-app there is core-js "^2.6.5" in dependencies. So I guess it needs core-js version 2, and it is able to work with core-js-compat in version 3, but after adding core-js version 3, it breaks.
So I currently have to stay with 1.9.1 and wait till nuxt goes to core-js 3, I guess. Gonna write an issue there also.
I think this issue may be closed.
Ok, I found the solution. Nuxt needs v2, and it is possible to force usage of v2 or v3: https://nuxtjs.org/guide/release-notes#v2.6.0 (core-js part)
I can confirm that 1.11.3-alpha-bb009c96.52 solves it. I have a minimal repro below, now working with the new version.
I was experiencing this error and in conjunction to "Not all operations have a unique name", I experience a failure to generate a fragment That is, sometimes the error would occur, sometimes not, and when it didn't it looks like a fragment would failure to show up in my generated files. However reverting my local installation to 1.9.1 resolved both of these issues.
@mmacheerpuppy Could you please try the given canary version above?
@ardatan Will do!
@ardatan Yep seems to have repaired the side effect on my end.
@ardatan Although it seems to have removed all the GraphQL comments from my generated source file, worth noting in case that raises any red-flags on your end, I'm not sure if this is intended behavior or if I'm missing a config-diff somewhere down the line. This is also present between 1.9.1 and 1.11.2.
@mmacheerpuppy I guess it's related to: https://github.com/dotansimha/graphql-code-generator/issues/3249
@dotansimha That's fine, thanks for all your hard work!
Fixed in v1.12.0
@dotansimha
seems like we do not get any Not all operations have an unique name error at all, now.
v1.12.2 - generates everything with duplicated typings e.g. for react.
v1.9.1 - does not generate and prints the expected error
@KillerCodeMonkey You should probably raise that as a separate issue :+1:
Most helpful comment
Fixed in
v1.12.0