Repository navigation
Override the types of input object custom scalar fields - #147
Closed
saga-dasgupta wants to merge 1 commit into
Closed
saga-dasgupta wants to merge 1 commit into
saga-dasgupta wants to merge 1 commit into
Conversation
`typegen` now takes `custom_scalar_overrides`, like `query` does, to override the type of a custom scalar field of an input object. Paths are `"InputObject.field"`, and lists and nullability are kept. This lets a field typed with a catch-all scalar such as `JSON` use a specific Rust type instead of an untyped value. Parsing and validation are shared with the `query` option, whose behaviour doesn't change.
saga-dasgupta
added a commit
to Shopify/shopify-function-rust
that referenced
this pull request
Oct 5, 2026
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#146 and Shopify/bluejay#147, patched in from #146's
branch, which has both, until they ship in a release.
saga-dasgupta
marked this pull request as ready for review
October 6, 2026 13:37
Contributor
Author
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.
querytakescustom_scalar_overridesto give a custom scalar in a query's output a specific Rust type. Input objects have no equivalent, so a field typed with a catch-all scalar such asJSONcan only be the scalar's type, usually an untyped value.This adds the same option to
typegen, for custom scalar fields of input objects:"InputObject.field", and the field's base type must be a custom scalar. Lists and nullability are kept, somyScalarabove becomesOption<i32>andmyScalarListbecomesVec<i32>. oneOf input objects are covered too, for their variants.::are relative to the schema module, as withquery.'alifetime, and needsborrow = true, as withquery.borrow = true.CustomScalarOverridegetsparse_allandvalidate_all, which both options now use. Thequeryoption's behaviour and error messages don't change.Compatibility
Nothing that compiles on
mainchanges: the option is new, and without it the generated types are the same.