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

fix: Add deprecated directive to enumsAsConst

Open nebbles opened this issue 1 year ago • 2 comments

Description

When generating standard enums, the comments for enum values are created with deprecated directives transformed into jsdoc. This PR fixes an issue where using enumsAsConst results in an object with comments that have not included the deprecated directives where relevant.

Related #9453 (fixes it)

Details

Use the BaseTypesVisitor getNodeComment to build the comment string (which uses transformComment under the hood) rather than just using the transform. The getNodeComment method already has support for intepreting and transforming deprecated directives correctly, as is seen in the default output for enums.

Approach

When looking at the EnumTypeDefinition within TsVisitor a special case is made for if this.config.enumsAsConst where it was building the enum values with a less advanced comment generator (transformComment utility). However in the default logic —when this config option is not enabled— the buildEnumValuesBlock method (from BaseTypesVisitor) is used which is implemented using the getNodeComment method. getNodeComment added support for recognising deprecated directives a few years back, and does so before applying transformComment to the result.

Type of change

Bug fix (non-breaking change which fixes an issue) but changes output by including deprecated directive where it previously was not.

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [ ] Test A
  • [ ] Test B

Test Environment:

  • OS:
  • @graphql-codegen/...:
  • NodeJS:

Checklist:

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

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

nebbles avatar Feb 01 '25 09:02 nebbles

🦋 Changeset detected

Latest commit: d2911c54f0d592e5e938d206fe72701af693e900

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

This PR includes changesets to release 9 packages
Name Type
@graphql-codegen/visitor-plugin-common Minor
@graphql-codegen/typescript-document-nodes Patch
@graphql-codegen/gql-tag-operations Patch
@graphql-codegen/typescript-operations Patch
@graphql-codegen/typescript-resolvers Patch
@graphql-codegen/typed-document-node Patch
@graphql-codegen/typescript Patch
@graphql-codegen/graphql-modules-preset Patch
@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 Feb 01 '25 09:02 changeset-bot[bot]

Any guidance on how this could be tested to prevent regressions would be appreciated

nebbles avatar Feb 01 '25 09:02 nebbles