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

fix: Add deprecated directive to enumsAsConst #10274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nebbles
Copy link
Contributor

@nebbles nebbles commented Feb 1, 2025

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...

Copy link

changeset-bot bot commented Feb 1, 2025

🦋 Changeset detected

Latest commit: d2911c5

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

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.
@nebbles nebbles force-pushed the patch-enumsasconst-missing-deprecated branch from fa60ded to d2911c5 Compare February 1, 2025 09:05
@nebbles
Copy link
Contributor Author

nebbles commented Feb 1, 2025

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

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

Successfully merging this pull request may close these issues.

1 participant