1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//! Crate to write Shopify Functions in Rust.
//!
//! This crate provides some convenience when building Shopify Functions using
//! Rust. The crate takes care of generating the required Rust structs to handle
//! the data types being passed between Shopify and the Function. The crate also
//! takes care of deserializing the input data and serializing the output data.
//!
//! ```ignore
//! use shopify_function::prelude::*
//!
//! #[typegen("./schema.graphql")]
//! mod schema {
//! #[query("./input.graphql")]
//! pub mod input {}
//! }
//!
//! #[shopify_function]
//! fn run(input: schema::input::Input) -> Result<schema::FunctionRunResult> {
//! /* ... */
//! }
//! ```
compile_error!;
pub use ;
pub type Result<T> = Result;
/// Runs the given function `f` with the invocation payload, returning the
/// deserialized output. This function is provided as a helper when writing
/// tests.
pub use shopify_function_wasm_api as wasm_api;
/// Each `compile_fail` case differs in one way from the first case, which compiles. Stable rustdoc
/// doesn't check error codes, so the first case is what keeps the others from failing for an
/// unrelated reason.
///
/// ```
/// # use shopify_function::prelude::*;
/// # #[typegen("tests/fixtures/prepare_schema.graphql", enums_as_str = ["__TypeKind"], custom_scalar_overrides = {
/// # "TargetPrepareResult.variables" => target_run::InputVariables,
/// # })]
/// # mod schema {
/// # #[query("tests/fixtures/prepare_run.graphql")]
/// # pub mod target_run {}
/// # }
/// # fn main() {}
/// fn prepare() -> schema::TargetPrepareResult {
/// schema::TargetPrepareResult {
/// variables: schema::target_run::InputVariables {
/// handle: "tier-a".to_string(),
/// first: Some(10),
/// },
/// }
/// }
/// ```
///
/// ```compile_fail,E0308
/// # use shopify_function::prelude::*;
/// # use shopify_function::scalars::JsonValue;
/// # use std::collections::BTreeMap;
/// # #[typegen("tests/fixtures/prepare_schema.graphql", enums_as_str = ["__TypeKind"], custom_scalar_overrides = {
/// # "TargetPrepareResult.variables" => target_run::InputVariables,
/// # })]
/// # mod schema {
/// # #[query("tests/fixtures/prepare_run.graphql")]
/// # pub mod target_run {}
/// # }
/// # fn main() {}
/// // A hand-written `JsonValue`.
/// fn prepare() -> schema::TargetPrepareResult {
/// schema::TargetPrepareResult {
/// variables: JsonValue::Object(BTreeMap::from([(
/// "handle".to_string(),
/// JsonValue::String("tier-a".to_string()),
/// )])),
/// }
/// }
/// ```
///
/// ```compile_fail,E0063
/// # use shopify_function::prelude::*;
/// # #[typegen("tests/fixtures/prepare_schema.graphql", enums_as_str = ["__TypeKind"], custom_scalar_overrides = {
/// # "TargetPrepareResult.variables" => target_run::InputVariables,
/// # })]
/// # mod schema {
/// # #[query("tests/fixtures/prepare_run.graphql")]
/// # pub mod target_run {}
/// # }
/// # fn main() {}
/// // `$handle` is declared but not set.
/// fn prepare() -> schema::TargetPrepareResult {
/// schema::TargetPrepareResult {
/// variables: schema::target_run::InputVariables { first: Some(10) },
/// }
/// }
/// ```
///
/// ```compile_fail,E0560
/// # use shopify_function::prelude::*;
/// # #[typegen("tests/fixtures/prepare_schema.graphql", enums_as_str = ["__TypeKind"], custom_scalar_overrides = {
/// # "TargetPrepareResult.variables" => target_run::InputVariables,
/// # })]
/// # mod schema {
/// # #[query("tests/fixtures/prepare_run.graphql")]
/// # pub mod target_run {}
/// # }
/// # fn main() {}
/// // `$tierHandle` is not what the query declares.
/// fn prepare() -> schema::TargetPrepareResult {
/// schema::TargetPrepareResult {
/// variables: schema::target_run::InputVariables {
/// tier_handle: "tier-a".to_string(),
/// first: Some(10),
/// },
/// }
/// }
/// ```
///
/// ```compile_fail,E0308
/// # use shopify_function::prelude::*;
/// # #[typegen("tests/fixtures/prepare_schema.graphql", enums_as_str = ["__TypeKind"], custom_scalar_overrides = {
/// # "TargetPrepareResult.variables" => target_run::InputVariables,
/// # })]
/// # mod schema {
/// # #[query("tests/fixtures/prepare_run.graphql")]
/// # pub mod target_run {}
/// # }
/// # fn main() {}
/// // `$first` is an `Int`.
/// fn prepare() -> schema::TargetPrepareResult {
/// schema::TargetPrepareResult {
/// variables: schema::target_run::InputVariables {
/// handle: "tier-a".to_string(),
/// first: Some("10".to_string()),
/// },
/// }
/// }
/// ```
;