Repository navigation
Type a prepare result's variables with its run query's variables type - #141
Closed
saga-dasgupta wants to merge 2 commits into
Closed
saga-dasgupta wants to merge 2 commits into
saga-dasgupta wants to merge 2 commits into
Conversation
…query Add typegen.js, which Shopify CLI runs instead of graphql-code-generator when this package has it (Shopify/cli#8829). It generates the function's types with the codegen plugins this package depends on, whatever the app's package manager hoists. It then exits non-zero, failing the build, when a prepare target returns variables its run query doesn't accept. The check is moved here from Shopify/cli#8829: it follows what the prepare export returns, ignoring type annotations and casts, and validates it against the run query's variable definitions.
Add @shopify/shopify_function/codegen, a plugin to use instead of typescript, with the same output. It takes customScalarOverrides to give a custom scalar field of an input object another type. typegen.js uses it in place of typescript, and gives each prepare result's variables its run query's variables type, so editors report mismatches.
saga-dasgupta
force-pushed
the
saga/custom-scalar-overrides
branch
from
November 10, 2026 20:24
73807fd to
266f89a
Compare
Contributor
Author
|
Closing for now: #140 switched to a build check instead of taking over typegen, so this no longer applies on top of it. The branch stays, for when we choose how to deliver editor types. |
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.
Stacked on #140.
Why
With #140, a prepare target's mismatched variables fail the build. Editors still can't show the mistake while you write it, because the generated type for the prepare result's
variablesisunknown.What
typegen.jsgives each prepare result'svariablesits run query's variables type. The prepare target's existing return type then lets editors underline unknown, missing and mistyped variables as you type. It's the editor side of Shopify/shopify-function-rust#252.To do this, it adds
@shopify/shopify_function/codegen, whichtypegen.jsuses in place of thetypescriptplugin. It generates the same types, and takescustomScalarOverridesto give a custom scalar field of an input object another type. Lists, nullability and oneOf variants are kept, and it can also be used when running codegen yourself.Tested
tests/typegen.test.cjs: the prepare result'svariablesgets the run query's variables type, and overrides from the config keep lists, nullability and oneOf variants. Invalid overrides fail codegen.variablesis typed with the run query's variables, and the build results match Fail the build when a prepare target's variables don't match its run query #140.