Add GraphQL name sanitization utilities#55
Merged
FionaBronwen merged 1 commit intofeature/graphqlfrom Jan 15, 2026
Merged
Conversation
65f55e7 to
0bc74f1
Compare
steverice
requested changes
Jan 8, 2026
894989c to
8dbe441
Compare
steverice
approved these changes
Jan 15, 2026
| /** Generate a string representation of template arguments (e.g., `StringAndInt`). */ | ||
| export function getTemplateString( | ||
| type: Type, | ||
| options: { conjunction: string } = { conjunction: "And" }, |
Author
There was a problem hiding this comment.
Yeah it's used to construct Union names and templated model names!
8dbe441 to
f5fca8d
Compare
FionaBronwen
added a commit
that referenced
this pull request
Mar 13, 2026
## Summary Adds utility functions for transforming TypeSpec names into valid GraphQL identifiers. These utilities form the foundation for name handling throughout the GraphQL emitter. ## Changes - **`src/lib/type-utils.ts`** - Core utility functions for GraphQL name transformations - **`test/lib/type-utils.test.ts`** - Unit tests for `sanitizeNameForGraphQL` ## Utilities Added | Function | Purpose | |----------|---------| | `sanitizeNameForGraphQL` | Sanitize names to be valid GraphQL identifiers | | `toTypeName` | Convert to PascalCase for type names | | `toFieldName` | Convert to camelCase for field names | | `toEnumMemberName` | Convert to CONSTANT_CASE for enum members | | `getUnionName` | Generate names for anonymous unions | | `getTemplatedModelName` | Generate names for templated models (e.g., `ListOfString`) | | `isArray`, `isRecordType` | Type guards for array/record models | | `unwrapModel`, `unwrapType` | Extract element types from arrays | | `isTrueModel` | Check if a model should emit as GraphQL object type | | `getGraphQLDoc` | Extract doc comments for GraphQL descriptions |
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
Adds utility functions for transforming TypeSpec names into valid GraphQL identifiers. These utilities form the foundation for name handling throughout the GraphQL emitter.
Changes
src/lib/type-utils.ts- Core utility functions for GraphQL name transformationstest/lib/type-utils.test.ts- Unit tests forsanitizeNameForGraphQLUtilities Added
sanitizeNameForGraphQLtoTypeNametoFieldNametoEnumMemberNamegetUnionNamegetTemplatedModelNameListOfString)isArray,isRecordTypeunwrapModel,unwrapTypeisTrueModelgetGraphQLDoc