Shopify GraphQL更新产品category字段报错:Field is not defined on ProductInput
问题解决:Shopify API更新产品分类报错
错误提示已经明确指出核心问题:category字段并未定义在ProductInput类型中,所以你提到的两种修改方式(调整请求selector、将category改为对象格式)都无法解决问题——因为这个字段本身就不是ProductInput的合法参数。
正确的更新方式
Shopify GraphQL API中,更新产品分类需要使用taxonomyCategoryId参数(而非category),直接传入分类的GID即可。
正确的Mutation请求
mutation ProductUpdate($input: ProductInput!) { productUpdate(input: $input) { product { id title category { id } } userErrors { field message } } }
正确的变量内容
{ "input": { "id": "gid://shopify/Product/9819449721123", "taxonomyCategoryId": "gid://shopify/TaxonomyCategory/aa-1-10-2" } }
补充说明
- 请求中保留
category { id }是正确的,这是用于查询更新后分类信息的返回字段,无需修改。 - 变量仅需替换参数名:把
category改为taxonomyCategoryId,值仍使用分类的GID字符串即可。
内容的提问来源于stack exchange,提问作者Dustin Oprea
相关产品推荐
相关产品推荐

