graphql - 如何在 Shopify 中使用 GraphQL 更新商店元字段

标签 graphql shopify shopify-api

如何在 Shopify 中使用 GraphQL 创建/更新商店元字段? 我可以使用以下内容轻松创建集合元字段:

mutation {
  collectionUpdate(
    input: {
      id: "gid"
      metafields: [
        {
          namespace: "testNamespace"
          key: "testKey"
          value: "someValue2"
          valueType: STRING
        }
        {
          id: "gid"
          value: "value"
        }
      ]
    }
  ) {
    collection {
      id
      metafields(first: 10) {
        edges {
          node {
            id
            value
          }
        }
      }
    }
    userErrors {
        field
        message
      }
  }
}

但这家商店似乎没有类似的东西。 此外,可以使用以下方式检索商店元字段:

{
  shop {
    metafield(namespace:"namespace",key:"key") {
          id
          value
        }
  }
}

最佳答案

要更新任何元字段,您可以使用突变“metafieldsSet

mutation setMetafield($metafields: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields:$metafields){
    metafields{
      id
      key
      value
    }
    userErrors{
      code
      message
    }
  }
}

MetafieldsSetInput 需要所有者 ID,您可以从商店查询中获取该 ID

query shopDetails{
  shop{
    id
  }
}

关于graphql - 如何在 Shopify 中使用 GraphQL 更新商店元字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68379403/

相关文章:

javascript - 使用 PHP 更新产品详细信息的 Shopify Api

graphql - 如何从 Shopify API 获取应用订阅状态

javascript - 从多对多关系中获取结果

javascript - 为什么 Github 的 GraphQL API 401 与 Axios 兼容?

php - 如何在此液体 for 循环上添加迭代

html - 如何在shopify网站中添加自定义字体

python - 在 Shopify 中向订单时间线添加评论

shopify - 使用 Shopify API 计算总销售额

javascript - GraphQL 参数如何与字段关联?

node.js - 在连接字符串密码字段中使用 Promise 返回数据库未连接