Skip to content

Add naming pipelines, buildTypeGraph, and printMutatedType to mutation engine#88

Merged
swatkatz merged 2 commits into
feature/graphqlfrom
feature/graphql-naming-mutations
Jun 8, 2026
Merged

Add naming pipelines, buildTypeGraph, and printMutatedType to mutation engine#88
swatkatz merged 2 commits into
feature/graphqlfrom
feature/graphql-naming-mutations

Conversation

@swatkatz

@swatkatz swatkatz commented Jun 8, 2026

Copy link
Copy Markdown

Summary

  • Moves all naming transforms into the mutation engine — after mutation, type.name is the final GraphQL identifier
  • Adds buildTypeGraph for packaging mutated types into a self-contained TypeGraph (ref: Timothee's TypeGraph concept)
  • Adds printMutatedType for stringifying mutation output as GraphQL type strings
  • Splits monolithic test file into 9 focused files

New modules

Module Purpose
src/lib/naming.ts Ordered naming pipelines (strip namespace → sanitize → case convert → suffixes)
src/lib/template-composition.ts Recursive template name composition using TemplatedType
src/mutation-engine/type-graph.ts buildTypeGraph + TypeGraph interface (inter-stage/inter-emitter contract)
src/mutation-engine/print-type.ts printMutatedType — renders mutation output as GraphQL type string

Naming pipeline design

Transforms are declared as ordered lists — order enforced by position:

const typeNamePipeline = [stripNamespace, sanitizeForGraphQL, toPascalCase, applyInterfaceSuffix, applyInputSuffix];
const fieldNamePipeline = [sanitizeForGraphQL, toCamelCase];
const enumMemberPipeline = [sanitizeForGraphQL, toConstantCase];

Context-dependent suffixes (Input, Interface) are pipeline steps that no-op when their flag is false.

Test plan

  • 189 tests pass (18 test files)
  • Build compiles cleanly (tsc -p .)
  • Type check clean (no errors in new/modified files)
  • Prettier formatted
  • Naming pipeline unit tests (19 tests)
  • Template composition tests with recursive nesting (7 tests)
  • buildTypeGraph tests including stage chaining (8 tests)
  • printMutatedType tests covering all nullability combinations (10 tests)
  • Mutation integration tests verifying pipelines are wired (8 tests)
  • Union oneOf naming consistency (snake_case → PascalCase + camelCase)

🤖 Generated with Claude Code

…MutatedType

Moves all naming transforms into the mutation engine so that after mutation,
every type.name is its final GraphQL identifier. The renderer never touches names.

New modules:
- src/lib/naming.ts: Ordered naming pipelines (type, field, enum member, base)
  with declared transform lists for visibility and enforced ordering.
- src/lib/template-composition.ts: Recursive template name composition
  (PaginatedModel<AdAccount> → PaginatedModelOfAdAccount).
- src/mutation-engine/type-graph.ts: buildTypeGraph + TypeGraph interface for
  packaging mutated types into a self-contained walkable namespace.
- src/mutation-engine/print-type.ts: printMutatedType for stringifying mutation
  engine output as GraphQL type strings (e.g., "[String!]!").

Modified mutations to use full naming pipeline:
- Models: PascalCase + Interface suffix + Input suffix + template composition
- Properties: camelCase
- Enums: PascalCase
- Enum members: CONSTANT_CASE
- Operations: camelCase
- Scalars: PascalCase (user-defined only)
- Unions: consistent naming for oneOf models, wrapper models, and fields

Test restructuring:
- Split monolithic graphql-mutation-engine.test.ts (1071 lines) into 9 focused
  test files by concern (enums, models, operations, scalars, unions, context,
  naming-integration, type-graph, print-type).
- Nullability tests now assert GraphQL type strings via printMutatedType
  for readability (e.g., expect(...).toBe("[String]!")).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment thread packages/graphql/src/lib/type-utils.ts Outdated
Comment thread packages/graphql/src/lib/naming.ts
Removes the confusing double-parenthesis formatting from the negated
boolean expression. Each exclusion condition is now a clear guard clause.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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