[WIP] Rearchitect GraphQL Emitter to use Alloy.js component-based approach#61
Draft
FionaBronwen wants to merge 17 commits intofionabronwen/graphql-mutation-engine-v2from
Draft
Conversation
## 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 |
aad8f78 to
14c0688
Compare
4ab36ef to
c4d5642
Compare
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.
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.
a05a236 to
79ea773
Compare
14c0688 to
a0869c7
Compare
Co-authored-by: Steve Rice <srice@pinterest.com>
Co-authored-by: Steve Rice <srice@pinterest.com>
Co-authored-by: Steve Rice <srice@pinterest.com>
Co-authored-by: Steve Rice <srice@pinterest.com>
Co-authored-by: Steve Rice <srice@pinterest.com>
Rewrite the GraphQL emitter using @alloy-js/graphql components and @typespec/emitter-framework for program context management. The new architecture uses JSX components for each GraphQL type (object, input, enum, scalar, union, interface) with a context-based system for type resolution and field analysis. Key changes: - Add Alloy.js component tree for GraphQL SDL generation - Add emitter-framework TspContext for program access via useTsp() - Add visibility-based input/output type classification - Replace old emitter.ts/graphql-emitter.ts/schema-emitter.ts with component-based emitter.tsx - Add comprehensive test suite (184 tests)
Dissolve design-doc-examples.test.ts, coverage-gaps.test.ts, emitter.test.ts, and diagnostics.test.ts — distribute their tests into feature-focused files. Create new files for unions, enums, arrays, deprecation, circular references, and doc comments. 197 tests across 17 files (was 197 across 15).
75dca02 to
8b85d6f
Compare
70e7589 to
84b7764
Compare
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
@alloy-js/coreand@alloy-js/graphqlcomposable
<GraphQLSchema>,<ObjectType>,<InputType>,<Field>, etc. componentsmutation engine from previous PR
Why Alloy.js?
The previous emitter used an imperative visitor pattern that manually constructed GraphQL AST nodes. This was difficult to extend and didn't make use of the TSP Emitter Framework. Alloy.js lets us express the GraphQL schema as a component tree where each TypeSpec type maps to a JSX component (
<ObjectType>,<EnumType>,<UnionType>, etc.).The
@alloy-js/graphqlpackage handles SDL rendering, so our components focus purely on the TypeSpec-to-GraphQL mapping logic. This makes the emitter easier to read, test, and extend.Want to run this branch locally?
The
@typespec/graphqlpackage depends on a local link to the Alloy repo viapnpm overrides in
pnpm-workspace.yaml. Both repos need to be siblings in thesame parent directory. The GraphQL emitter uses Alloy's graphql-js bindings,
which live on the
feature/graphql-jsbranch in Alloy.Clone both repos as siblings
git clone git@github.com:pinterest/typespec.gitgit clone https://github.com/pinterest/alloy.gitAlloy: check out the graphql-js bindings branch
cd alloy && git checkout feature/graphql-jspnpm install && pnpm build:allcd ..TypeSpec: check out the component emitter branch
cd typespec && git checkout fionabronwen/graphql-component-emitterpnpm install && pnpm -C packages/graphql run buildRun the emitter against the sample schema
pnpm -C packages/graphql tsp compile test/main.tsp --emit @typespec/graphqlOutput schema in:
packages/graphql/tsp-output/@typespec/graphql/schema.graphql