Graphql-code-generator: Enums with numeric values defined in enumValues are not generated correctly

Created on 17 Dec 2019  路  3Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug

There are two, enum given numeric values in enumValues config options are generated as string and value 0 will not be converted at all

To Reproduce
Steps to reproduce the behavior:

give numeric values to map enum fields in enumValues config option

  1. My GraphQL schema:
enum FooEnum {
  FOO
  BAR
}
  1. My GraphQL operations:

no problems with operation, just with generated type, graphql will convert correctly

  1. My codegen.yml config file:
overwrite: true
schema: './data/schema.graphql'
documents: null
generates:
  packages/api/src/generated/schema.ts:
    plugins:
      - add: '/* istanbul ignore file */'
      - typescript
      - typescript-resolvers
    config:
      namingConvention:
        enumValues: keep
      enumValues:
        FooEnum:
          FOO: 1
          BAR: 0

Expected behavior

The generated code should be

export enum FooEnum {
  FOO = 1
  BAR = 0
}

but it is

export enum FooEnum {
  FOO = '1'
  BAR = 'BAR'
}

https://codesandbox.io/s/graphql-codegen-issue-template-1lmxr

Environment:

  • OS: Linux
  • @graphql-codegen/...:
{
    "@graphql-codegen/add": "^1.8.3",
    "@graphql-codegen/cli": "^1.9.1",
    "@graphql-codegen/introspection": "^1.9.1",
    "@graphql-codegen/typescript": "^1.9.1",
    "@graphql-codegen/typescript-resolvers": "^1.9.1",
}
  • NodeJS: 12.13.0

Additional context

graphql will convert correctly because I have the enum resolver defined explicitly as

export const resolvers = {
  FooEnum: {
    FOO: 1,
    BAR: 0,
  },
};
bug plugins waiting-for-release

All 3 comments

@BigsonLvrocha I think I managed to fix that in: https://github.com/dotansimha/graphql-code-generator/pull/3187

Can you please try 1.9.2-alpha-4be25b2b.82?

Available in v1.10.0.

I was on a trip, got the computer now, it's fixed, thanks :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SimenB picture SimenB  路  3Comments

dotansimha picture dotansimha  路  3Comments

leonardfactory picture leonardfactory  路  3Comments

NickClark picture NickClark  路  3Comments

iamdanthedev picture iamdanthedev  路  3Comments