Add rename-types transformer to graphql package #53
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