@@ -10,66 +10,68 @@ A crate to help developers build [Shopify Functions].
1010
1111See the [ example_with_targets] for details on usage, or use the following guide to convert an existing Rust-based function.
1212
13- ## Updating an existing function using a version of ` shopify_function ` below ` 0.9.0 ` to use version ` 0.9.0 ` and above
14-
15- 1 . In ` main.rs ` , add imports for ` shopify_function ` .
16-
17- ``` rust
18- use shopify_function :: prelude :: * ;
19- use shopify_function :: Result ;
20- ```
21-
22- 1 . In `main . rs`, add type generation , right under your imports . Remove any references to the `generate_types! ` macro . Replace `. / input . graphql` with the location of your input query file (e . g. `src / run . graphql`).
23-
24- ```rust
25- #[typegen(" ./schema.graphql" )]
26- pub mod schema {
27- #[query(" ./input.graphql" )]
28- pub mod input {}
29- }
30- ```
31-
32- If your Function has multiple targets each with their own input query , add a nested module for each . For example :
33- ```rust
34- #[typegen(" ./schema.graphql" )]
35- pub mod schema {
36- #[query(" src/target_a.graphql" )]
37- pub mod target_a {}
38-
39- #[query(" src/target_b.graphql" )]
40- pub mod target_b {}
41- }
42- ```
43-
44- 1 . In `main . rs`, ensure that you have a `main ` function that returns an error indicating to invoke a named export :
45-
46- ```rust
47- fn main () {
48- eprintln! (" Invoke a named import" );
49- std :: process :: exit (1 );
50- }
51- ```
52-
53- 1 . Throughout all of your source files , replace any references to `#[shopify_function_target]` with the `shopify_function ` macro , and change its return type . Typically , this is located in a file with a name equal to the target , e . g. `run . rs`.
54-
55- ```rust
56- #[shopify_function]
57- fn run (input : schema :: input :: Input ) -> Result <schema :: FunctionRunResult > {
58- ```
59-
60- 1 . Update the types and fields utilized in the function to the new , auto - generated structs . For example :
61- | Old | New |
62- | --- | --- |
63- | `input :: ResponseData ` | `schema :: input :: Input ` |
64- | `input :: InputDiscountNodeMetafield ` | `schema :: input :: input :: discount_node :: Metafield ` |
65- | `input :: InputDiscountNode ` | `schema :: input :: input :: DiscountNode ` |
66- | `output :: FunctionRunResult ` | `schema :: FunctionRunResult ` |
67- | `output :: DiscountApplicationStrategy :: FIRST ` | `schema :: DiscountApplicationStrategy :: First ` |
68-
69- If referencing generated types from a file other than `main . rs` where they are defined , you 'll need to import the schema . For example in `run . rs` you would need to add :
70- ```rust
71- use crate :: schema;
72- ```
13+ ## Updating an existing function using a version of ` shopify_function ` below ` 1.0.0 ` to use version ` 1.0.0 ` and above
14+
15+ 1 . In ` main.rs ` , add imports for ` shopify_function ` .
16+
17+ ``` rust
18+ use shopify_function :: prelude :: * ;
19+ use shopify_function :: Result ;
20+ ```
21+
22+ 1 . In `main . rs`, add type generation , right under your imports . Remove any references to the `generate_types! ` macro . Replace `. / input . graphql` with the location of your input query file (e . g. `src / run . graphql`).
23+
24+ ```rust
25+ #[typegen(" ./schema.graphql" )]
26+ pub mod schema {
27+ #[query(" ./input.graphql" )]
28+ pub mod input {}
29+ }
30+ ```
31+
32+ If your Function has multiple targets each with their own input query , add a nested module for each . For example :
33+
34+ ```rust
35+ #[typegen(" ./schema.graphql" )]
36+ pub mod schema {
37+ #[query(" src/target_a.graphql" )]
38+ pub mod target_a {}
39+
40+ #[query(" src/target_b.graphql" )]
41+ pub mod target_b {}
42+ }
43+ ```
44+
45+ 1 . In `main . rs`, ensure that you have a `main ` function that returns an error indicating to invoke a named export :
46+
47+ ```rust
48+ fn main () {
49+ eprintln! (" Invoke a named import" );
50+ std :: process :: exit (1 );
51+ }
52+ ```
53+
54+ 1 . Throughout all of your source files , replace any references to `#[shopify_function_target]` with the `shopify_function ` macro , and change its return type . Typically , this is located in a file with a name equal to the target , e . g. `run . rs`.
55+
56+ ```rust
57+ #[shopify_function]
58+ fn run (input : schema :: input :: Input ) -> Result <schema :: FunctionRunResult > {
59+ ```
60+
61+ 1 . Update the types and fields utilized in the function to the new , auto - generated structs . For example :
62+ | Old | New |
63+ | --- | --- |
64+ | `input :: ResponseData ` | `schema :: input :: Input ` |
65+ | `input :: InputDiscountNodeMetafield ` | `schema :: input :: input :: discount_node :: Metafield ` |
66+ | `input :: InputDiscountNode ` | `schema :: input :: input :: DiscountNode ` |
67+ | `output :: FunctionRunResult ` | `schema :: FunctionRunResult ` |
68+ | `output :: DiscountApplicationStrategy :: FIRST ` | `schema :: DiscountApplicationStrategy :: First ` |
69+
70+ If referencing generated types from a file other than `main . rs` where they are defined , you 'll need to import the schema . For example in `run . rs` you would need to add :
71+
72+ ```rust
73+ use crate :: schema;
74+ ```
7375
7476## Viewing the generated types
7577
0 commit comments