Skip to content

Conversation

@FionaBronwen
Copy link

@FionaBronwen FionaBronwen commented Dec 4, 2025

Summary

This PR adds the rename-types transform to the @typespec/graphql package, which sanitizes TypeSpec type names into valid GraphQL identifiers using the new compiler transformer infrastructure.

What It Does

The rename-types transform applies sanitizeNameForGraphQL() to:

  • Models - $My-Model$_My_Model_
  • Model properties - my.propmy_prop
  • Enums - My.EnumMy_Enum
  • Enum members - 123value_123value
  • Operations - my-querymy_query
  • Scalars - $CustomScalar$_CustomScalar_

The sanitization replaces non-word characters with underscores and prefixes names starting with numbers.

Usage

# tspconfig.yaml
transformer:
  extends: ["@typespec/graphql/graphql_naming"]

Or enable individually:

transformer:
  enable:
    "@typespec/graphql/rename-types": true

Changes

File Description
src/transformers/rename-types.transform.ts Transform definition with mutation classes for each type kind
src/transformer.ts Exports $transformer with the graphql_naming transform set
src/lib/type-utils.ts sanitizeNameForGraphQL() utility (existing file, function already present)
test/transformers/rename-types.transform.test.ts Comprehensive tests for all type kinds
package.json Added @typespec/mutator-framework dependency

Testing

pnpm -F @typespec/graphql exec vitest run test/transformers/rename-types.transform.test.ts

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