Skip to content

v1.1.1: Metafield, Enum types are not supported #169

@seka19

Description

@seka19

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions