【发布时间】:2026-01-18 15:35:01
【问题描述】:
我已经编写了我的第一个使用 GraphQL 的脚本(仍然是一个学习曲线)
目前我正在使用 GraphQL 进行 3 次调用, 首先是产品查找, 其次是价格更新, 第三是库存更新。
为了减少对终点的调用次数,我想合并价格更新和库存,但是我的运气为 0,我不知道它的格式是否错误。
这是我的 GraphQL 代码(我正在使用 Postman 来帮助确保架构正确,然后再将其带到 PHP 中)
mutation productVariantUpdate($input: ProductVariantInput!) {
productVariantUpdate(input: $input) {
product {
id
}
productVariant {
id
price
}
userErrors {
field
message
}}
second: inventoryActivate($inventoryItemId: ID!, $locationId: ID!, $available: Int) {
inventoryActivate(inventoryItemId: $inventoryItemId, locationId: $locationId, available: $available) {
inventoryLevel {
id
available
}
userErrors {
field
message
}
}
}
}
变量:
{
"inventoryItemId": "gid://shopify/InventoryItem/XXXXXXXXXXX",
"locationId": "gid://shopify/Location/XXXXXXXXXX",
"available": 11 ,
"input": {
"id": "gid://shopify/ProductVariant/XXXXXXXXX",
"price": 55
}
}
我不断收到错误:
{
"errors": [
{
"message": "Parse error on \"$\" (VAR_SIGN) at [29, 29]",
"locations": [
{
"line": 29,
"column": 29
}
]
}
]
}
【问题讨论】: