Shopify / Shopify/shopify-function-rust
v1.1.1: Metafield, Enum types are not supported
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 47
- Forks
- 9
- Avg merge
- 1h 53m
- Merged PRs (30d)
- 2
Description
The issue is described in detail, with examples, here:
https://community.shopify.dev/t/rust-shopify-function-crate-1-1-1-enum-deserialization-limitation/21739
In version 0.8.0, it was possible to pass fully custom input types into a function (while still using the generated types for the function's output):
use serde::Deserialize;
use shopify_function::prelude::*;
use shopify_function::Result;
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct InputData {
pub discount_node: InputDiscountNode,
pub presentment_currency_rate: Decimal,
pub cart: InputCart,
}
#[shopify_function_target(query_path = "blank.graphql", schema_path = "schema.graphql")]
fn run(input: InputData) -> Result<output::FunctionRunResult> {
...
}
This way, I could separately describe the structure of all input data needed by my function, including the JSON from a metafield (which is large, complex, and contains many Enums).
It worked efficiently and kept the code maintainable.
In version 1.1.1, the idea seems to have been to make things easier via custom_scalar_overrides, so that it would be enough to just describe the JSON structure and have it integrated into the generated types.
But it doesn't work if my JSON uses Enums: Error: Enum types are not supported for deriving Deserialize
At the same time, the trick of overriding the Input type, as in the old version, doesn't work anymore either:
error[E0277]: the trait bound `InputData: shopify_function::shopify_function_wasm_api::Deserialize` is not satisfied
Obviously, the #[shopify_function] macro checks that the input type implements the internal trait shopify_function::wasm_api::Deserialize, and plain serde::Deserialize is not enough.
But the internal shopify_function::wasm_api::Deserialize trait cannot handle Enums.
So, I really hope this issue will be addressed in future releases, because I'd prefer not to abandon Enums or write massive "workarounds" just for the sake of migrating.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the custom_scalar_overrides path, the #[shopify_function] macro, and the internal shopify_function::wasm_api::Deserialize trait described in the issue; compare their behavior between versions 0.8.0 and 1.1.1. Done means enum-containing metafield JSON can be deserialized and custom input types remain usable without requiring unsupported internal trait behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100