Commit 6e682f0
Add mutation engine for TypeSpec-to-GraphQL type transformation (#62)
## 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 |
* Add mutation engine for TypeSpec-to-GraphQL type transformation
Introduce a mutation engine that transforms TypeSpec types into
GraphQL-compatible forms using the mutator framework. Includes mutations
for enums, models, scalars, unions, and operations.
Also includes package hygiene: add tspMain, update node engine to >=20,
add api-extractor.json, CHANGELOG.md, fix testing casing, and clean up
dead code.
* cleanup
* Add input/output type context splitting to mutation engine
Operations automatically propagate input context to parameters and
output context to return types via GraphQLMutationOptions. The
framework's cache and options propagation handle nested types, so the
same source model produces separate input and output mutations without
any custom type-graph walking.
* Update packages/graphql/src/lib/scalar-mappings.ts
Co-authored-by: Steve Rice <srice@pinterest.com>
* Update packages/graphql/src/lib/scalar-mappings.ts
Co-authored-by: Steve Rice <srice@pinterest.com>
* Update packages/graphql/src/lib/scalar-mappings.ts
Co-authored-by: Steve Rice <srice@pinterest.com>
* Update packages/graphql/src/lib/scalar-mappings.ts
Co-authored-by: Steve Rice <srice@pinterest.com>
* Update packages/graphql/src/lib/scalar-mappings.ts
Co-authored-by: Steve Rice <srice@pinterest.com>
* Address PR comments
* Address additional comments
* Remove mutateModel variant
* Update to use typekit functions
* handle scalar extends based on PR feedback
* Handle input unions -> oneOf mutation
* Add specificationUrls for PlainDate, PlainTime, and BigDecimal scalars
Use scalars.graphql.org hosted specs per review feedback:
- PlainDate → andimarek/local-date
- PlainTime → apollographql/localtime-v0.1
- BigDecimal (decimal, decimal128) → chillicream/decimal
* Update packages/graphql/lib/specified-by.tsp
Co-authored-by: Steve Rice <srice@pinterest.com>
* Address feedback, round out nullability handling
* Carry nullability info in state map for nullable wrapper unions
---------
Co-authored-by: Steve Rice <srice@pinterest.com>1 parent c204b15 commit 6e682f0
30 files changed
Lines changed: 2491 additions & 27 deletions
File tree
- packages/graphql
- lib
- src
- lib
- mutation-engine
- mutations
- testing
- test
- lib
- mutation-engine
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 34 | + | |
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
40 | 38 | | |
| 39 | + | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
| |||
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
49 | | - | |
50 | | - | |
| 48 | + | |
| 49 | + | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
| |||
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
| 58 | + | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
139 | 157 | | |
140 | 158 | | |
141 | 159 | | |
| |||
149 | 167 | | |
150 | 168 | | |
151 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
152 | 176 | | |
153 | 177 | | |
154 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | 79 | | |
86 | 80 | | |
87 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | 10 | | |
14 | 11 | | |
15 | 12 | | |
| |||
0 commit comments