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

[TypeScript Resolvers] Some combinations of type names and field names causes duplicate identifier errors #1954

Closed
dobesv opened this issue Jun 2, 2019 · 11 comments
Labels
plugins waiting-for-release Fixed/resolved, and waiting for the next stable release

Comments

@dobesv
Copy link
Contributor

dobesv commented Jun 2, 2019

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.

@dotansimha
Copy link
Owner

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

@dobesv
Copy link
Contributor Author

dobesv commented Jun 5, 2019

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.

@dotansimha dotansimha changed the title Rename / exclude fields / type [TypeScript Resolvers] Some combinations of type names and field names causes duplicate identifier errors Jun 23, 2019
@ken0x0a
Copy link
Contributor

ken0x0a commented Jun 28, 2019

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

I'm sorry for noise 🙇‍♂️

@dotansimha
Copy link
Owner

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.

@mxstbr
Copy link
Contributor

mxstbr commented Jul 4, 2019

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.

@dotansimha dotansimha reopened this Jul 4, 2019
@dotansimha
Copy link
Owner

dotansimha commented Jul 4, 2019

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

@mxstbr
Copy link
Contributor

mxstbr commented Jul 4, 2019

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!

@mxstbr
Copy link
Contributor

mxstbr commented Jul 4, 2019

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?

mxstbr pushed a commit to mxstbr/graphql-code-generator that referenced this issue Jul 5, 2019
@mxstbr
Copy link
Contributor

mxstbr commented Jul 5, 2019

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

@dotansimha dotansimha added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Jul 6, 2019
@dotansimha
Copy link
Owner

dotansimha commented Jul 6, 2019

Fixed in: 0e67020
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.

@dotansimha
Copy link
Owner

Fixed in 1.4.0 🎉

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

No branches or pull requests

4 participants