我对 Shopify 应用程序开发还很陌生,所以如果我在这里遗漏了一些明显的东西,我深表歉意。
我正在构建一个 Shopify 应用程序,有时会在添加到购物车时添加额外的 CartLine 属性。我有这部分工作;当我调用
cart/add
api 时,如果选择了属性,我可以看到正在传递的属性。
现在我正在尝试添加 Shopify 折扣功能,它将使用这些属性(例如,field_a)。我使用本教程作为参考。
GraphQL 输入:
query Input {
cart {
lines {
attribute {
field_a
}
merchandise {
...on ProductVariant {
id
}
}
}
}
}
API.rs:
#[derive(Clone, Debug, Deserialize)]
pub struct CartLine {
pub quantity: Int,
pub merchandise: Merchandise,
pub attribute: AttributeList,
}
#[derive(Clone, Debug, Deserialize)]
pub struct AttributeList {
#[serde(default="_default_false")]
pub field_a: i64,
}
fn _default_false() -> i64 { 0 }
但是,当我尝试部署我的 Shopify 应用程序时,出现以下错误。这好像是因为field_a在被查询的数据中并不总是可用的?
│ The deployment of functions failed with the following errors:
│ [
│ {
│ "field": null,
│ "message": "Field 'field_a' doesn't exist on type 'Attribute' at 'query
│ Input.cart.lines.property.field_a'", │
│ "tag": "input_query_validation_error"
│ }
│ ]
有人对我修复这个错误有建议吗?我尝试将 field_a 定义为选项,并尝试为整个 AttributeList 结构设置默认值,但是当我运行
npm run deploy
.... 时,我不断收到相同的错误
query Input {
cart {
lines {
field_a: attribute (key: "field_a") {
value
}
merchandise {
...on ProductVariant {
id
}
}
}
}
}
field_a 是别名。不必匹配钥匙