graphql-code-generator: Duplicate identifier error

Describe the bug Duplicate resolver type is generated.

To Reproduce

  1. Define field category_sports: category as schema. (single underscore)
  2. Define another field category__sports: [category] as schema. (double underscore)
  3. Run the following command: gql-gen -s http://somewhere/graphql -t graphql-codegen-typescript-template -o ./src/resolvers/types.ts ./src/resolvers/query.ts
  4. Run the following command: tsc -p . src/resolvers/types.ts - error TS2300: Duplicate identifier ‘CategorySportsResolver’.

Expected behavior No error message.

Environment:

  • OS: macOS High Sierra
  • Codegen: graphql-code-generator v0.12.5, graphql-codegen-typescript-template@0.12.5
  • Node: v8.12.0

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 9
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@dotansimha @danbruegge, Faced the same problem.

It happens because "pluginCreator___id" and "pluginCreatorId" using change-case#pascalCase is transformed into the same PluginCreatorId.

Changing the enum transformer name convention to keep solved the problem:

# codegen.yaml
config:
  namingConvention:
    enumValues: keep

Hi, looks like this error is back again? We have a simple GatsbyJS+StrapiJS stack.

This is what i get:

src/graphqlTypes.ts:868:3 - error TS2300: Duplicate identifier 'PluginCreatorId'.

868   PluginCreatorId = "pluginCreator___id",
      ~~~~~~~~~~~~~~~

src/graphqlTypes.ts:932:3 - error TS2300: Duplicate identifier 'PluginCreatorId'.

932   PluginCreatorId = "pluginCreatorId",

Do you need further infos?

It happens also for me when my schema contains both _id and id fields. It generates twice the type IdResolver

@panzerdp nice, it works great. Thank you. 😃

It seems the duplicate resolver type is happening in in 0.15.2. I just upgraded from 0.13. I had resolvers turned off there but decided to give it a try after the upgrade but ran into Typescript build errors due to the duplicates. I have some types in my schema with legacy fields that are in snake_case (such as brand_id) but have new fields in camelCase (brandId).

I think I could use a custom namingConvention to workaround but would be great If it was handled by the package.

Btw, I love this project! Great work and thanks!