简体   繁体   English

如何在 Shopify 中使用 GraphQL 更新 Shop Metafields

[英]How to update Shop Metafields using GraphQL in Shopify

How can I create/update a shop metafield using GraphQL in shopify?如何在 shopify 中使用 GraphQL 创建/更新商店元字段? I could easily create a collection metafield using the following:我可以使用以下方法轻松创建集合元字段:

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
      }
  }
}

But there seems to be no equivalent for the shop.但是这家商店似乎没有等价物。 Also, a shop metafield can be retrieved using:此外,可以使用以下方法检索商店元字段:

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

To Update any metafield you can use the mutation " metafieldsSet "要更新任何元字段,您可以使用突变“ metafieldsSet

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

MetafieldsSetInput Requires owner id which you can get from shop query MetafieldsSetInput需要您可以从商店查询中获得的所有者 ID

query shopDetails{
  shop{
    id
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM