dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.87k stars 1.34k forks source link

Error: Unable to merge GraphQL directive "abstractEntity" #6944

Open dwalker93 opened 3 years ago

dwalker93 commented 3 years ago

Describe the bug Codegen worked fine with "@graphql-codegen/add": "^3.1.0", "@graphql-codegen/cli": "1.21.7", "@graphql-codegen/typescript": "1.23.0", "@graphql-codegen/typescript-resolvers": "1.20.0", "@graphql-codegen/typescript-mongodb": "^1.19.5", and then accidently updated all packages to latest. Then got TypeError:

yarn gen
  √ Parse configuration
  > Generate outputs
    > Generate ./src/generated/graphql.ts
      √ Load GraphQL schemas
      √ Load GraphQL documents
      × Generate
        →       directive @abstractEntity(additionalFields: [AdditionalEntityFields], discriminatorField: String!) on INTERFACE

 Found 1 error

  ✖ ./src/generated/graphql.ts
    Error: Unable to merge GraphQL directive "abstractEntity".
    Existing directive:
        directive @abstractEntity(discriminatorField: String!, additionalFields: [AdditionalEntityFields]) on INTERFACE
    Received directive:
        directive @abstractEntity(additionalFields: [AdditionalEntityFields], discriminatorField: String!) on INTERFACE
        at validateInputs (<path-to-project>\node_modules\@graphql-tools\merge\index.js:162:15)
        at mergeDirective (<path-to-project>\node_modules\@graphql-tools\merge\index.js:167:9)
        at mergeDirective (<path-to-project>\node_modules\@graphql-tools\merge\index.js:167:9)
        at mergeGraphQLNodes (<path-to-project>\node_modules\@graphql-tools\merge\index.js:589:49)
        at mergeGraphQLTypes (<path-to-project>\node_modules\@graphql-tools\merge\index.js:658:25)
        at Object.mergeTypeDefs (<path-to-project>\node_modules\@graphql-tools\merge\index.js:605:22)
        at makeExecutableSchema (<path-to-project>\node_modules\@graphql-tools\schema\index.js:496:38)
        at Object.mergeSchemas (<path-to-project>\node_modules\@graphql-tools\schema\index.js:534:12)
        at Object.codegen (<path-to-project>\node_modules\@graphql-codegen\core\index.js:128:18)
        at process (<path-to-project>\node_modules\@graphql-codegen\cli\bin.js:1003:67)
        at Array.map (<anonymous>)

Something went wrong

my codegen config

hooks:
  afterAllFileWrite:
    - prettier --write
require:
  - ts-node/register
overwrite: true
schema: ./src/types/index.ts
definitions:
  add: &top-comment
    content: >
      /**
       * NOTE: THIS IS AN AUTO-GENERATED FILE. DO NOT MODIFY IT DIRECTLY.
       */

      /* eslint-disable */
generates:
  ./src/generated/graphql.ts:
    plugins:
      - add: *top-comment
      - 'typescript'
      - 'typescript-mongodb'
      - 'typescript-resolvers'
    config:
      avoidOptionals: true
      useIndexSignature: true
      scalars:
        DateTime: Date
        EmailAddress: string
        NonNegativeFloat: number
        NonNegativeInt: number

Retried with rollbacking to different versions and fixed the error with older versions. And again updated one by one to latest and found the bug in graphql-codegen/cli starting from v2.

Working Sandbox (With prev versions) : https://codesandbox.io/s/cranky-bush-ojj8p

To Reproduce Error Recreated in: https://codesandbox.io/s/relaxed-perlman-mdrwp

Environment:

Urigo commented 3 years ago

Hi @dwalker93 and thank you for the report

Sorry but I'm not adding a lot here but just labeling it according to our new Contribution Guide and issue flow.

It seems already got into stage 1 thanks to your reproduction! Thank you for that!

Now in order to advance to stage 2 we'll need a failing test, would be great if someone could help progress the issues through the stages.

Thank you and sorry that this comment is not a complete solution (yet).

wolffparkinson commented 2 years ago

Anything on this one ? Issue is reproducible with @graphql-codegen/cli v2.4.0 as well

dwalker93 commented 2 years ago

still there's no solution for version above from 2.0. But you can downgrading cli to 1.21.7. It works fine with all other updated latest packages.