Repository navigation
Conversation
mssalemi
force-pushed
the
ms.handle-null-fields-wasm-api
branch
from
June 27, 2025 14:33
254911c to
269b04c
Compare
mssalemi
commented
Jun 27, 2025
| /// Uses conservative detection to identify Optional fields from GraphQL schema | ||
| fn is_input_field_nullable(ivd: &impl InputValueDefinition) -> bool { | ||
| // Use std::any::type_name to get type information as a string | ||
| let type_name = std::any::type_name_of_val(&ivd.r#type()); |
Contributor
Author
There was a problem hiding this comment.
Not super familiar with bluejay, but I think if we have something like:
ivd.r#type().is_nullable()
Then we could avoid using this approach. We need to get the type information so we can match correctly. I ran into issues when trying to use matching because some types were required (aka not optional), and some were optional.
Contributor
There was a problem hiding this comment.
Yeah we should be using bluejay here for the type information
mssalemi
force-pushed
the
ms.handle-null-fields-wasm-api
branch
from
June 27, 2025 15:18
269b04c to
1b4199b
Compare
adampetro
reviewed
Jul 3, 2025
Comment on lines
+545
to
566
| // Generate field counting statements for dynamic field count calculation | ||
| let field_count_statements: Vec<syn::Stmt> = input_object_type_definition | ||
| .input_field_definitions() | ||
| .iter() | ||
| .map(|ivd| { | ||
| let field_name_ident = names::field_ident(ivd.name()); | ||
|
|
||
| if is_input_field_nullable(ivd) { | ||
| // For nullable fields, count only if Some(_) | ||
| parse_quote! { | ||
| context.write_utf8_str(#field_name_lit_str)?; | ||
| }, | ||
| if let ::std::option::Option::Some(_) = self.#field_name_ident { | ||
| field_count += 1; | ||
| } | ||
| } | ||
| } else { | ||
| // For required fields, always count | ||
| parse_quote! { | ||
| self.#field_name_ident.serialize(context)?; | ||
| }, | ||
| ] | ||
| field_count += 1; | ||
| } | ||
| } | ||
| }) | ||
| .collect(); |
Contributor
There was a problem hiding this comment.
Can we just consolidate this into one line where we pre-compute the number of non-nullable fields and add the rest based on value, e.g. we might end up with:
let field_count: usize = 5 + self.foo.is_some().into() + self.bar.is_some().into();
saga-dasgupta
added a commit
that referenced
this pull request
Oct 8, 2026
0.5.0 is published with Shopify/bluejay#148 and #149, so the macro depends on it and the workspace no longer patches the bluejay crates in from #149's branch, which is deleted now that it's merged.
makrisoft
pushed a commit
that referenced
this pull request
Oct 13, 2026
* Type prepare results with the run query's variables struct
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.
* Update bluejay to Shopify/bluejay#149's rebased branch
* Use bluejay 0.5.0
0.5.0 is published with Shopify/bluejay#148 and #149, so the macro depends on it and the workspace
no longer patches the bluejay crates in from #149's branch, which is deleted now that it's merged.
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.
Addresses: https://github.com/shop/issues-shopifyvm/issues/318
Summary
What this PR does?
Before:
{ "attributes": null, "image": null, "price": null, "title": "Something that is wrapped" }After:
{ "title": "Something that is wrapped" }Approach
Testing
Pro's