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

Yah*_*ein 2 shopify graphql 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
      }
  }
}
Run Code Online (Sandbox Code Playgroud)

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

{
  shop {
    metafield(namespace:"namespace",key:"key") {
          id
          value
        }
  }
}
Run Code Online (Sandbox Code Playgroud)

AKA*_*ANI 5

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

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

Run Code Online (Sandbox Code Playgroud)

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

query shopDetails{
  shop{
    id
  }
}
Run Code Online (Sandbox Code Playgroud)