【发布时间】:2021-11-25 16:20:35
【问题描述】:
我试图使用metafieldsSet 突变来更新Shopify 中的元字段,代码如下:
const client = new Shopify.Clients.Graphql(
process.env.SHOP,
process.env.PASSWORD
)
try {
const metafields = await client.query({
data: `mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
userErrors {
field
message
}
metafields {
key
value
}
}
}
`,
query: {
metafields: [
{
key: 'cb_inventory',
namespace: 'my_fields',
ownerId: 'gid://shopify/ProductVariant/40576138313890',
type: 'number_integer',
value: '25',
},
],
},
})
console.log(metafields)
res.status(200).json({ values: metafields })
} catch (error) {
console.log(error)
res.status(500).json(error)
}
但是,上述突变返回以下错误:
Expected value to not be null
Variable $metafields of type [MetafieldsSetInput!]! was provided invalid value
我假设变量 metafields 未能传递到突变中,因为当我在 Shopify Admin API GraphiQL explorer 中运行完全相同的突变时,没有错误
Shopify Admin API GraphiQL explorer mutation result
我还查看了@shopify/shopify-api 的github repo。在我的理解中,变量被添加到query 对象中。
我错过了什么?
谢谢,
霍华德
环境:下一个 js 11.1.2,
依赖:@shopify/shopify-api1.4.1
【问题讨论】: