Rust support in Shopify Functions
You can write your functions in Rust. This guide describes the Rust crate that Shopify provides to help developers build with Shopify Functions.
RequirementsAnchor link to section titled "Requirements"
You need to have
graphql_client installed as a dependency in your project:
How it worksAnchor link to section titled "How it works"
Rust crate bundles
graphql_client-based type generation, reduces boilerplate code, and makes it easier to unit testing various function inputs. Rust crate includes the following components:
||A macro that enables you to do the following:
||An attribute macro that marks the following function as the entry point for a function. It manages the function's
||A utility for unit testing that enables you to add new tests based on a given JSON input string.|
Viewing the generated typesAnchor link to section titled "Viewing the generated types"
To preview the types generated by the
generate_types macro, use the
cargo doc command.
Example implementationAnchor link to section titled "Example implementation"
Explore an example implementation of Shopify Function Rust crate.
Update an existing functionAnchor link to section titled "Update an existing function"
You can update an existing function written in Rust to use the
In your project, run
cargo add shopify_function.
cargo add firstname.lastname@example.org.
main.rs, complete the following steps:
Add imports for
Remove references to
Add type generation directly under your imports:
functionfunction with the
shopify_functionmacro, and change its return type:
Update the types and fields utilized in the function to the new, auto-generated structs. The following table provides an example:
- Explore the reference documentation for crate