graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

feat(presets/client): support `enumsAsConst` option

Open azu opened this issue 1 year ago • 5 comments
trafficstars

Description

Add enumsAsConst to client presets.

Related

  • https://github.com/dotansimha/graphql-code-generator/issues/8562#issuecomment-2137815225
  • https://github.com/dotansimha/graphql-code-generator/issues/9072

Edit:

This PR is duplicated of https://github.com/dotansimha/graphql-code-generator/pull/9574, but this includes a test.

Type of change

Please delete options that are not relevant.

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update

Screenshots/Sandbox (if appropriate/relevant):

Add Unit Test

How Has This Been Tested?

  • Add a test case for enumsAsConst
  • Run npm test

Test Environment:

  • OS: macOS
  • @graphql-codegen/...: latest
  • NodeJS:v18.19.0

Checklist:

  • [x] I have followed the CONTRIBUTING doc and the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [x] Any dependent changes have been merged and published in downstream modules

Further comments

client preset already support enumsAsType. I think that it should support enumsAsConst too.

azu avatar May 29 '24 15:05 azu

🦋 Changeset detected

Latest commit: 21e7d1fb7884eacfc907cf5716fc335c6dce1949

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-codegen/client-preset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar May 29 '24 15:05 changeset-bot[bot]

Ah, I notice that this PR is duplicated of https://github.com/dotansimha/graphql-code-generator/pull/9574, but this PR includes a test.

azu avatar May 29 '24 15:05 azu

@n1ru4l Thanks. I've added enumsAsConst to website/src/pages/plugins/presets/preset-client.mdx https://github.com/dotansimha/graphql-code-generator/pull/9981/commits/c9a3511c6b5ce8f58b6740a3daafede5c4c9d22f

azu avatar Jun 07 '24 00:06 azu

@azu maybe worth re-requesting review from @n1ru4l now that you've made the requested changes? Would be great to see this land in client-preset.

nebbles avatar Aug 10 '24 10:08 nebbles

+1 to this change, this would resolve several headaches for my org.

sampsonjoliver avatar Sep 18 '24 07:09 sampsonjoliver

Great work @azu, this would be an amazing change for us as well if it could get merged! I’d be more than happy to help if needed to make this happen @n1ru4l

Note: While waiting for the official change, you can throw this dirty little workaround into a package.json script to get the job done 😱 grep -q 'enumsAsConst' node_modules/@graphql-codegen/client-preset/cjs/index.js || sed -i '' '/enumsAsTypes: options.config.enumsAsTypes,/s/$/ enumsAsConst: options.config.enumsAsConst,/' node_modules/@graphql-codegen/client-preset/cjs/index.js

SimonTernoir avatar Nov 16 '24 17:11 SimonTernoir