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

graphql-modules-preset: Accept enumsAsConst for typescript plugin config #9072

Open
kensukesaito opened this issue Feb 26, 2023 · 0 comments

Comments

@kensukesaito
Copy link

kensukesaito commented Feb 26, 2023

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

enumsAsConst is ignored:

import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
  schema: './src/modules/**/typedefs/*.graphql',
  generates: {
    './src/modules/': {
      preset: 'graphql-modules',
      presetConfig: {
        baseTypesPath: '../generated-types/graphql.ts',
        filename: 'generated-types/module-types.ts',
      },
      plugins: [
        {
          typescript: {
            enumsAsConst: true, // ❌ Does not work
          },
        },
        {
          'typescript-resolvers': {}
        },
      ],
    },
  },
}

export default config

because graphql-modules-preset overwrites typescript plugin config as enumsAsTypes: true, so enumsAsConst: true is ignored.

config: {
  ...options.config,
  enumsAsTypes: true, // 🙁
},

https://github.com/dotansimha/graphql-code-generator/blob/master/packages/presets/graphql-modules/src/index.ts#L69

Describe the solution you'd like

Accept a config something like this in ModulesConfig:

export type ModulesConfig = {
  ...
  disableOverwritesEnumsAsConfig: boolean;
  ...
};

https://github.com/dotansimha/graphql-code-generator/blob/master/packages/presets/graphql-modules/src/config.ts

import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
  schema: './src/modules/**/typedefs/*.graphql',
  generates: {
    './src/modules/': {
      preset: 'graphql-modules',
      presetConfig: {
        baseTypesPath: '../generated-types/graphql.ts',
        filename: 'generated-types/module-types.ts',
        disableOverwritesEnumsAsConfig: true, // ✅ Add
      },
      plugins: [
        {
          typescript: {
            enumsAsConst: true, // ✅ Works!
          },
        },
        {
          'typescript-resolvers': {}
        },
      ],
    },
  },
}

export default config

Describe alternatives you've considered

No response

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

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant