Skip to content

Conversation

thekevinbrown
Copy link

@thekevinbrown thekevinbrown commented Aug 20, 2025

Add special handling for identifiers that consist entirely of _ when we are asked to remove underscores. Added a test for this behaviour as well.

Description

Our GraphQL schema includes an enum which has _ as a value. This currently results in invalid syntax in the generated types file.

Related # (issue): #10411

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • 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):

Code Sandbox

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

  • Unit test added to ensure special behaviour when transformUnderscore: true, and the passed in strings consist entirely of _ characters.

Test Environment:

Jest, CI

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

…we are asked to remove underscores. Added a test for this behaviour as well.
Copy link

changeset-bot bot commented Aug 20, 2025

🦋 Changeset detected

Latest commit: 7ed74e3

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 Patch
@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

@eddeee888
Copy link
Collaborator

Hi @thekevinbrown,
Thanks for looking into this!

One thought I have is packages/plugins/other/visitor-plugin-common/src/utils.ts is a core package that is used across all plugins. I think it's less risky if this PR is scoped to your use case of enums.

If we see this needs to be applied across the board, we could consider your proposed implementation.

Here's how we scope it to just enum options:

  • Here's the call that converts the name.
  • We could check if the option name is _ and apply transformUnderscore: false ?
  • We could add tests specifically to the typescript plugin here since it's the main plugin that generates enums (and I believe is used by most users)

@thekevinbrown
Copy link
Author

No worries, will update this to be scoped to just that case.

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.

2 participants