Repository navigation
Type prepare results with the run query's variables struct - #252
Open
saga-dasgupta wants to merge 2 commits into
Open
saga-dasgupta wants to merge 2 commits into
saga-dasgupta wants to merge 2 commits into
Conversation
saga-dasgupta
force-pushed
the
prepare-run-variables
branch
2 times, most recently
from
October 5, 2026 16:58
f8a12e4 to
bdddfb5
Compare
saga-dasgupta
force-pushed
the
prepare-run-variables
branch
from
October 5, 2026 18:25
bdddfb5 to
157b6e5
Compare
saga-dasgupta
force-pushed
the
prepare-run-variables
branch
3 times, most recently
from
October 5, 2026 21:34
c661396 to
5385b4a
Compare
A prepare target returns the variables for its run target's input query as
untyped `JSON`. Nothing checked that they matched what the run query declares,
so a renamed, added, or retyped variable deployed fine and failed at checkout,
with the run query resolving nothing.
bluejay now generates a struct for the variables of each operation that
declares them: `<Operation>Variables`, or `RootVariables` for an anonymous
operation, with a field per variable. A non-null variable with no default is a
plain field; any other is an `Option` whose `None` omits it. `typegen`
implements wasm_api's `Serialize` and `Deserialize` for it with the same code
as input objects, so it serializes directly.
bluejay's `typegen` also takes `custom_scalar_overrides`, so a prepare result's
`variables` field can be typed as the run query's variables struct instead of
`JsonValue`:
#[typegen("schema.graphql", custom_scalar_overrides = {
"CartValidationsGeneratePrepareResult.variables" => cart_validations_generate_run::InputVariables,
})]
A prepare target that no longer matches its run query then fails to compile:
- a renamed or removed variable is an unknown field (E0560)
- an added variable is a missing field (E0063)
- a retyped variable, or a hand-written `JsonValue`, is a mismatch (E0308)
Depends on Shopify/bluejay#149 and Shopify/bluejay#148, patched in from
Shopify/bluejay#149's branch, which has both, until they ship in a release.
saga-dasgupta
force-pushed
the
prepare-run-variables
branch
from
October 6, 2026 14:33
5385b4a to
0174886
Compare
saga-dasgupta
marked this pull request as ready for review
October 6, 2026 14:38
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.
Why
A prepare target returns the variables for its run target's input query as untyped
JSON. Nothing checks that they match what the run query declares. A renamed, added, or retyped variable deploys fine, and then the run query resolves nothing at checkout.What
Depends on two bluejay PRs:
<Operation>Variables, orRootVariablesfor an anonymous operation. A non-null variable with no default is a plain field; any other is anOptionwhoseNoneomits the key, so the query's default applies.custom_scalar_overridestotypegen, to type a custom scalar field of an input object as another type.The first is based on the second. Until both ship in a release, the workspace
Cargo.tomlpatches the bluejay crates in from Shopify/bluejay#149's branch.typegenimplements wasm_api'sSerializeandDeserializefor the variables struct through bluejay's newCodeGeneratorhooks. The struct reuses the code input objects already use, moved into a sharedobject_impls, so it serializes directly.Overriding the prepare result's
variablesfield then types it as the run query's variables struct instead ofJsonValue:A prepare target that no longer matches its run query fails to compile:
JsonValueBreaking change
SerializeandDeserialize, andDebug,PartialEqandClone. This applies to any#[query]module, not only run queries. Input objects already need these. The built-in mappings (String,JsonValue,Decimal) all have them.Limits
String,ID, and the custom scalars mapped toString(such asHandle) are the same Rust type, so switching between them doesn't fail to compile.$self,$Self,$super,$crateor$_panics the macro, the same way fields with those names already do. Both are covered in Generate a struct for each operation's variables bluejay#149.