feat: implement sequential stages PoC for plugin output hand-off - #10945
Draft
eddeee888 wants to merge 1 commit into
Draft
feat: implement sequential stages PoC for plugin output hand-off#10945eddeee888 wants to merge 1 commit into
eddeee888 wants to merge 1 commit into
Conversation
Small, additive proof-of-concept for the RFC's recommended "Sequential
Stages" design: a `generates` entry can be an array of `{ plugins }` /
`{ preset }` stage objects that run one after another against the same
output path, instead of only the existing plugins-within-one-stage
parallel execution.
- `Types.SequentialStages` (`ConfiguredOutput[]`) is a new accepted shape
for `generates[path]`, alongside the existing `ConfiguredOutput` and
`ConfiguredPlugin[]` shorthand. `isSequentialStagesArray()` tells the two
array shapes apart by checking for a `plugins`/`preset` key on each item.
- `@graphql-codegen/core`'s `codegen()` gains an optional
`onPluginOutput` callback, so a caller can observe each plugin's raw
`Types.PluginOutput` (including `meta`) without changing its existing
`Promise<string>` return type.
- The CLI (`executeCodegen`) runs a stages array through a dedicated code
path: stages execute sequentially (not via `Promise.all`), a stage's
`meta` (collected via `onPluginOutput`) is threaded into the next
stage's `pluginContext.previousStageMeta`, and stage outputs are
concatenated into one `FileOutput`.
- `normalizeOutputParam()` also accepts a stages array (merging each
stage's `schema`/`documents`/`watchPattern`) so existing callers like
watch-mode pattern matching don't break.
Scope/limitations of this PoC (by design, to keep it small):
- No per-stage `schema`/`documents` overrides - stages share the root
`schema`/`documents`.
- No `documentTransforms`/hooks/`contentComparison` per stage.
- `{ preset }` stages are accepted by the type/detection but not executed
by the CLI's stages loop yet.
Demonstrated end-to-end in
`packages/graphql-codegen-cli/tests/sequential-stages.spec.ts` using two
toy plugins standing in for `typescript` -> `typescript-resolvers`: the
second stage's plugin reads the first stage's `meta`
(`pluginContext.previousStageMeta`) instead of re-deriving it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xva2iGJ4Xw5GYGAHxyCEra
|
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.
Description
This PR implements a proof-of-concept for RFC #10943 ("Sequential Execution & Output Hand-off Between GraphQL Codegen Plugins/Presets"), specifically Option 1: Sequential Stages.
What Changed
The implementation allows
generatesentries to be defined as an array of stage objects (instead of just a singleConfiguredOutput), where:metathat is passed to the next stage viapluginContext.previousStageMeta, keyed by plugin nameKey Modifications
packages/graphql-codegen-cli/src/codegen.ts: AddedgeneratesStagescollection and sequential stage execution logic with proper schema/document loading and meta threadingpackages/utils/plugins-helpers/src/helpers.ts: AddedisSequentialStagesArray()type guard to distinguish sequential stages from plugin arrays, and updatednormalizeOutputParam()to handle stagespackages/utils/plugins-helpers/src/types.ts:SequentialStagestype definitiononPluginOutputcallback toGenerateOptionsfor observing plugin output and metageneratesconfig to acceptSequentialStagespackages/graphql-codegen-core/src/codegen.ts: AddedonPluginOutputcallback invocation to expose plugin output to callersTesting
Added comprehensive test suite (
sequential-stages.spec.ts) with:pluginContext.previousStageMetageneratesentriesAdded fixture plugins (
sequential-stage-1.js,sequential-stage-2.js) demonstrating the meta hand-off pattern.Backward Compatibility
✅ Fully backward compatible - existing single-stage
generatesentries continue to work as before. The new array syntax is opt-in.Related #10943
https://claude.ai/code/session_01Xva2iGJ4Xw5GYGAHxyCEra