Graphql-code-generator: [TypeScript Resolvers] Some combinations of type names and field names causes duplicate identifier errors

Created on 2 Jun 2019  ·  11Comments  ·  Source: dotansimha/graphql-code-generator

Is your feature request related to a problem? Please describe.

I have a situation like:

type Whatever {
  itemTags: [ItemTag!]
}
type WhateverItem {
  tags: [ItemTag!]
}

When resolver types are generated, it generated two types with the same name WhateverItemTags.

Describe the solution you'd like

Ideally I could somehow rename the resolver type for one of these.

Describe alternatives you've considered

I think the only way to work around this is to assign a different name to one of the fields.

bug plugins waiting-for-release

Most helpful comment

I created a minimal reproduction here:

https://github.com/dobesv/graphql-codegen-1954

Check out the repo and run yarn && yarn repro to reproduce the issue.

All 11 comments

@dobesv can you please share the codegen and plugins version, and the output you got?

I created a minimal reproduction here:

https://github.com/dobesv/graphql-codegen-1954

Check out the repo and run yarn && yarn repro to reproduce the issue.

I deleted comment as it was my mistake and graphql-code-generator was works perfectly.

I'm sorry for noise 🙇‍♂️

Hi @dobesv, I noticed that your repro is using a very old version of the codegen (0.18.2).

I tested the latest version with the updated dependencies:

{
  "name": "graphql-codegen-1954",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {},
  "devDependencies": {
    "@graphql-codegen/cli": "1.3.1",
    "graphql": "^14.3.1",
    "@graphql-codegen/typescript-resolvers": "1.3.1",
    "@graphql-codegen/typescript": "1.3.1"
  },
  "scripts": {
    "repro": "gql-gen && tsc resolverTypes.ts"
  }
}

And this config file:

overwrite: true
schema: Repro.graphql
generates:
  ./resolverTypes.ts:
    config:
      scalars:
        Date: Date
        JSON: any
    plugins:
      - typescript
      - typescript-resolvers

And everything seems to work, no compiler errors.

I am on the latest version of graphql-codegen and still getting an error like this: "Duplicate identifier 'PullRequestReviewThreadsArgs'" when running against the full GitHub GraphQL API (reference for how to set that up is in #2105)

I am on 1.3.1 across all plugins.

@mxstbr I tried now with the latest, it seems like it compiles correctly (there is only one PullRequestReviewThreadsArgs).
output example

Can you please create a minimal reproduction for this?

Hmm interesting, it might be because I am an employee and am hitting an internal GraphQL API. Let me try to get you a minimal reproduction!

I found the issue, this is the most minimal reproduction:

type PullRequest {
    reviewThreads(first: Int!): Int
}

type PullRequestReview {
    threads(first: Int!, last: Int!): Int
}

This generates two types with the same name, PullRequestReviewThreadsArgs, even though they are not the same!

@dotansimha do you think you can fix it with this information?

Submitted a failing test as a PR: #2111 This should hopefully help you fix this @dotansimha!

Fixed in: https://github.com/dotansimha/graphql-code-generator/commit/0e670203ed77609c56ba03e295e257cb4744265b
Available as alpha 1.3.1-alpha-a16b1dd1.74. You can now specify addUnderscoreToArgsType: true in the config and it will add _ to solve this issue.

Fixed in 1.4.0 🎉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rogerg93 picture rogerg93  ·  3Comments

iamdanthedev picture iamdanthedev  ·  3Comments

SimenB picture SimenB  ·  3Comments

leebenson picture leebenson  ·  3Comments

quolpr picture quolpr  ·  3Comments