Graphql-code-generator: Duplicate identifier error

Created on 23 Sep 2018  路  11Comments  路  Source: dotansimha/graphql-code-generator

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, [email protected]
  • Node: v8.12.0
bug core

Most helpful comment

@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

All 11 comments

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

It's related to the fact that our pascalCase handler does not bahave nicely with underscores. It removes them. We did a fix for it for fields that starts with _, but I guess that's not enough.

I'll take a look soon.

Thanks @shinyaohira for reporting it!

@kamilkisiela I tested it now, and it's related to the generated resolvers only. We need there a mechanism similar to the duplicates handler we have (or to patch pascalCase helper to ignore _ in the middle of the string). Can you please take a look?

@shinyaohira @geotry as a workaround for now, you can use CODEGEN_RESOLVERS=false on your environment variables, and it will skip the resolvers generation that causes this issue.

Fixed in >0.14

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!

@brandondoran we fixed this issue in the recent refactor, it will be available very soon in 1.0.0.

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

This is what i get:
```$ tsc --noEmit
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?

@danbruegge can you please open a new issue for that with all the info? It seems like it's a different issue.

@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

@panzerdp nice, it works great. Thank you. :)

If there is pluginCreatorId and pluginCreator_____Id
It generates one and only PluginCreatorId causing duplicate. Reproducible with gatsby-netlify-template schema.
With defaults e.g. PascalCase casing setup for enum.

So reopen and try to fix it somehow. Could cause a lot of headaches for some. For me is fine to change casing to keep, because I only start a project, but for some, it can be a no go problem.

Was this page helpful?
0 / 5 - 0 ratings