如何使用 Admin-graphql 在 Shopify 上创建私有元字段?在他们的文档中,他们给出了通过 ID 检索私有元字段的示例(参考:https://shopify.dev/api/admin-graphql/2022-01/queries/privateMetafield#section-examples),你知道吗?有使用 Node.js 创建私有元字段的示例吗?
我使用https://www.npmjs.com/package/shopify-api-node,它支持GraphQL调用。 https://insomnia.rest/ 具有出色的 GraphQL 支持,包括字段提示、查询评估等。
使用私有元字段创建产品的示例:
mutation productCreate($input: ProductInput!, $namespace: String!) {
productCreate(input: $input) {
product {
id
bufferProductId: privateMetafield(
key: "your_field_key"
namespace: $namespace
) {
value
}
tags
variants(first: 10) {
edges {
node {
id
sku
}
}
}
}
userErrors {
field
message
}
}
}
您需要将这些变量传递给 GraphQL 查询:
{
"input": {
"title": "Your product name",
"options": [
"Size",
"Colour"
],
"handle": "your-product-name",
"tags": [
"Product tag"
],
"vendor": "Lauri's sportin' goods",
"variants": [
{
"sku": "ABC123XL",
"options": [
"Large",
"Blue"
]
},
{
"sku": "ABC123L",
"options": [
"Large",
"Yellow"
]
}
],
"privateMetafields": [
{
"key": "your_field_key",
"namespace": "your_namespace",
"valueInput": {
"value": "Your field value",
"valueType": "STRING"
}
}
]
},
"namespace": "your_namespace"
}
这将在产品创建响应中返回私有元字段值。 私有元字段与公共元字段的一些不同之处:
这些字段类型来设置私有元字段值。