Skip to content

Replace legacy emitter with foundation skeleton and diagnostics#83

Open
FionaBronwen wants to merge 2 commits intofionabronwen/graphql-alloy-foundation-v2from
fionabronwen/graphql-foundation-skeleton
Open

Replace legacy emitter with foundation skeleton and diagnostics#83
FionaBronwen wants to merge 2 commits intofionabronwen/graphql-alloy-foundation-v2from
fionabronwen/graphql-foundation-skeleton

Conversation

@FionaBronwen
Copy link
Copy Markdown

@FionaBronwen FionaBronwen commented Apr 21, 2026

Summary

  • Delete the legacy emitter implementation (all type builders, the old $onEmit, and supporting files)
  • Stand up the new data-pipeline skeleton in emitter.ts covering Phases 1–4: type-usage analysis → mutation → classification → model-variant assignment.
  • Add two diagnostics to lib.ts:
    • empty-schema (warning) — emitted when classification produces no queries
    • void-operation-return (warning) — emitted for operations that return void
  • Wire the empty-schema guard into emitSchema and the void-operation-return filter into classifyTypes

Test plan

  • pnpm build succeeds
  • pnpm test — 142 tests pass (140 baseline + 2 new diagnostic tests)
    • New: empty-schema diagnostic is emitted when no queries are classified
    • New: void-operation-return diagnostic is emitted for void operations

@FionaBronwen FionaBronwen force-pushed the fionabronwen/graphql-alloy-foundation-v2 branch from 8b51ca4 to 8f411e1 Compare April 21, 2026 16:24
@FionaBronwen FionaBronwen force-pushed the fionabronwen/graphql-foundation-skeleton branch from afdf684 to ce78164 Compare April 21, 2026 16:25
@FionaBronwen FionaBronwen changed the title Fionabronwen/graphql foundation skeleton Replace legacy emitter with foundation skeleton and diagnostics Apr 21, 2026
@FionaBronwen FionaBronwen force-pushed the fionabronwen/graphql-foundation-skeleton branch from ce78164 to 5c566f6 Compare April 21, 2026 20:25
Removes the procedural GraphQL emitter and stands up the data-pipeline
skeleton that the upcoming Alloy component-based emitter will build on.

Deleted:
- graphql-emitter.ts (old procedural emitter)
- schema-emitter.ts (old schema-specific emitter)
- registry.ts (old type registry)
- type-maps.ts (old type mapping logic)
- test/emitter.test.ts tests for the legacy emitter

Rewrote src/emitter.ts as a four-phase data pipeline:
- Phase 1: type usage tracking (reachability / input-output marking)
- Phase 2: mutation (GraphQL naming via the mutation engine)
- Phase 3: classification (interfaces, output models, input models, ops)
- Phase 4: model variant lookups

The pipeline produces a SchemaPipelineResult bundle
(classifiedTypes, modelVariants, scalarSpecifications) that is handed
to a renderSchema stub. The stub is a no-op in this PR; component-based
SDL rendering, file emission, and the .tsx conversion land in follow-up
PRs. Introducing the SchemaPipelineResult type and the pipeline/renderer
seam here keeps the downstream PR reviewable on its own.

Also introduces two new diagnostics that the pipeline reports today:
- empty-schema: fires when a schema has no query root (GraphQL requires one)
- void-operation-return: fires when an operation returns void (no GraphQL
  equivalent; the operation is filtered out of the schema)

Test coverage added for both diagnostics in test/emitter.test.ts.
@FionaBronwen FionaBronwen force-pushed the fionabronwen/graphql-foundation-skeleton branch 2 times, most recently from b3a1c52 to 193c59a Compare April 22, 2026 17:00
The emitter used to walk the schema namespace itself, bucket types by kind,
dedup scalars, and run a second classification pass to split models into
input/output variants. That loop also leaked implementation details (an
`originalToMutated` back-map and a `TypeUsageResolver` that outlived
mutation) into the emitter's public shape.

Introduce `GraphQLMutationEngine.mutateSchema(schema, typeUsage)` that
returns a fully-classified `MutatedSchema`:

- Pre-bucketed models: `interfaces`, `outputModels`, `inputModels`
- Pre-classified operations: `queries`, `mutations`, `subscriptions`
- Derived metadata: `wrapperModels`, `scalarVariants`, `scalarSpecifications`

Classification happens inline during the walk. `typeUsage` is consumed
entirely inside the engine; the emitter hands it over and never touches
it again. `originalToMutated` no longer exists outside the engine.

Implementation lives in `src/mutation-engine/schema-mutator.ts` as a free
function called from the `GraphQLMutationEngine` class to avoid a circular
import between engine.ts and schema-mutator.ts.

The emitter's `emitSchema` reduces to: resolve type usage, call
`engine.mutateSchema`, report void-return diagnostics, check for empty
schema, build variant lookups, hand off to the (stubbed) renderer.
@FionaBronwen FionaBronwen force-pushed the fionabronwen/graphql-foundation-skeleton branch from 193c59a to 95f3757 Compare April 22, 2026 17:09
@FionaBronwen FionaBronwen marked this pull request as ready for review April 22, 2026 17:14
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.

1 participant