Add rename-types transformer to graphql package#53
Draft
FionaBronwen wants to merge 2 commits intofionabronwen/transformer-basefrom
Draft
Add rename-types transformer to graphql package#53FionaBronwen wants to merge 2 commits intofionabronwen/transformer-basefrom
FionaBronwen wants to merge 2 commits intofionabronwen/transformer-basefrom
Conversation
- Add rename-types.transform.ts for GraphQL name sanitization - Add sanitizeNameForGraphQL utility function - Add transformer.ts to define graphql transformer library - Add comprehensive tests for rename-types transform - Update package.json with mutator-framework dependency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds the
rename-typestransform to the@typespec/graphqlpackage, which sanitizes TypeSpec type names into valid GraphQL identifiers using the new compiler transformer infrastructure.What It Does
The
rename-typestransform appliessanitizeNameForGraphQL()to:$My-Model$→_My_Model_my.prop→my_propMy.Enum→My_Enum123value→_123valuemy-query→my_query$CustomScalar$→_CustomScalar_The sanitization replaces non-word characters with underscores and prefixes names starting with numbers.
Usage
Or enable individually:
Changes
src/transformers/rename-types.transform.tssrc/transformer.ts$transformerwith thegraphql_namingtransform setsrc/lib/type-utils.tssanitizeNameForGraphQL()utility (existing file, function already present)test/transformers/rename-types.transform.test.tspackage.json@typespec/mutator-frameworkdependencyTesting
pnpm -F @typespec/graphql exec vitest run test/transformers/rename-types.transform.test.ts