Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect "Not all operations have an unique name" on 1.11.2 #3326

Closed
benjie opened this issue Jan 20, 2020 · 32 comments
Closed

Incorrect "Not all operations have an unique name" on 1.11.2 #3326

benjie opened this issue Jan 20, 2020 · 32 comments
Assignees
Labels
core Related to codegen core/cli waiting-for-release Fixed/resolved, and waiting for the next stable release

Comments

@benjie
Copy link
Contributor

benjie commented Jan 20, 2020

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:

Screenshot_20200120_104824

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.

@lorado
Copy link

lorado commented Jan 20, 2020

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

@ardatan
Copy link
Collaborator

ardatan commented Jan 20, 2020

Could you try the following?

schema: ...
documents:
    - your-documents-pointer:
          skipGraphQLImport: true

@lorado
Copy link

lorado commented Jan 20, 2020

@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 }"

@benjie
Copy link
Contributor Author

benjie commented Jan 20, 2020

@ardatan Assuming I've got the YAML sigils in the correct places, this doesn't seem to have made any difference:

Screenshot_20200120_170633

@ardatan ardatan added bug waiting-for-release Fixed/resolved, and waiting for the next stable release and removed waiting-for-release Fixed/resolved, and waiting for the next stable release labels Jan 20, 2020
@will-hart
Copy link

will-hart commented Jan 21, 2020

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)

@ardatan
Copy link
Collaborator

ardatan commented Jan 21, 2020

Could you all try with the following version?
1.11.3-alpha-bb009c96.52

@lorado
Copy link

lorado commented Jan 21, 2020

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

@ardatan
Copy link
Collaborator

ardatan commented Jan 22, 2020

@benjie I see but as I asked in here;
#3328 (comment)
I need a clear minimal production to help your better. :)

@will-hart
Copy link

1.11.3-alpha-bb009c96.52 resolves my error above 👍

@dotansimha dotansimha added the core Related to codegen core/cli label Jan 22, 2020
@dotansimha
Copy link
Owner

It seems like latest version works, right? (1.11.3-alpha-bb009c96.52) @will-hart @ardatan @benjie

@dotansimha dotansimha added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Jan 22, 2020
@dotansimha
Copy link
Owner

@lorado it seems like an issue with nuxt/core-js, not sure it's related to the codegen...

@benjie
Copy link
Contributor Author

benjie commented Jan 22, 2020

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).

@lorado
Copy link

lorado commented Jan 22, 2020

@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: core-js@3.6.4.

Nuxt uses babel, and therefore install core-js-compat@3.6.4. 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.

@lorado
Copy link

lorado commented Jan 22, 2020

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)

@defrex
Copy link

defrex commented Jan 24, 2020

I can confirm that 1.11.3-alpha-bb009c96.52 solves it. I have a minimal repro below, now working with the new version.

https://codesandbox.io/s/cool-shape-v1cff

@caldempsey
Copy link

caldempsey commented Jan 26, 2020

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.

@ardatan
Copy link
Collaborator

ardatan commented Jan 26, 2020

@mmacheerpuppy Could you please try the given canary version above?

@caldempsey
Copy link

@ardatan Will do!

@caldempsey
Copy link

@ardatan Yep seems to have repaired the side effect on my end.

@caldempsey
Copy link

caldempsey commented Jan 26, 2020

@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.

@dotansimha
Copy link
Owner

@mmacheerpuppy I guess it's related to: #3249

@caldempsey
Copy link

@dotansimha That's fine, thanks for all your hard work!

@dotansimha
Copy link
Owner

Fixed in v1.12.0

@KillerCodeMonkey
Copy link

KillerCodeMonkey commented Feb 7, 2020

@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

@benjie
Copy link
Contributor Author

benjie commented Feb 7, 2020

@KillerCodeMonkey You should probably raise that as a separate issue 👍

@MincePie
Copy link

MincePie commented Dec 5, 2022

how did you fix this in react?

My packages are:

"@graphql-codegen/add": "3.2.1",
    "@graphql-codegen/cli": "2.13.7",
    "@graphql-codegen/typescript": "2.8.0",
    "@graphql-codegen/typescript-operations": "2.5.5",
    "@graphql-codegen/typescript-react-apollo": "3.3.5",

@MincePie
Copy link

@benjie how did you manage to get such a detailed error message in your console? I only get:

Generate outputs
  ❯ Generate to src/lib/graphql.tsx
    ✔ Load GraphQL schemas
    ✔ Load GraphQL documents
    ✖ Not all operations have an unique name: CreateGroup, AllGroups
Running lifecycle hook "afterStart" scripts... 

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.

@benjie
Copy link
Contributor Author

benjie commented Dec 12, 2022

🤷

@saihaj
Copy link
Collaborator

saihaj commented Dec 12, 2022

@MincePie can you try running codegen with env var DEBUG=1 graphql-codegen ?

@MincePie
Copy link

hi @saihaj

I get:

DEBUG=true graphql-codegen DEBUG=1 graphql-codegen
✔ Parse Configuration
⚠ Generate outputs
❯ Generate to src/lib/graphql.tsx
✔ Load GraphQL schemas
✔ Load GraphQL documents
✖ Not all operations have an unique name: CreateIssueGroup, AllIssueGroups
Running lifecycle hook "afterStart" scripts...
[CLI] Loading Schemas
[CLI] Loading Documents
[CLI] Generating output
error Command failed with exit code 1.

which is the same as I get without the debug

@saihaj
Copy link
Collaborator

saihaj commented Dec 12, 2022

and what version are you running @MincePie ?

@saihaj
Copy link
Collaborator

saihaj commented Dec 12, 2022

if it is on the latest version of codegen I would recommend you create a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli waiting-for-release Fixed/resolved, and waiting for the next stable release
Projects
None yet
Development

No branches or pull requests

10 participants