Skip to content

Instantly share code, notes, and snippets.

@klevu
Last active February 12, 2024 12:00
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klevu/32705fea16302cd1c49b70db4f181d4c to your computer and use it in GitHub Desktop.
Save klevu/32705fea16302cd1c49b70db4f181d4c to your computer and use it in GitHub Desktop.
Shopify Metafields with GraphQL
{
product(first: 50) {
edges {
node {
name
description
}
}
}
}
{
products(first: 250) {
edges {
node {
metafields(first: 250) {
edges {
node {
namespace
key
value
}
}
}
}
}
}
}
{
productVariants(first: 50) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
legacyResourceId
product {
legacyResourceId
}
metafield1: metafield(
namespace: "klevu"
key: "metafield1"
) {
value
}
metafield2: metafield(
namespace: "klevu"
key: "metafield2"
) {
value
}
metafield3: metafield(
namespace: "klevu"
key: "metafield3"
) {
value
}
}
}
}
}
mutation {
bulkOperationRunQuery(
query: """
{
products {
edges {
node {
id
metafields {
edges {
node {
namespace
key
value
}
}
}
variants {
edges {
node {
id
metafields {
edges {
node {
namespace
key
value
}
}
}
}
}
}
}
}
}
}
"""
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
@quyet-akr
Copy link

quyet-akr commented Feb 14, 2022


mutation {
  productUpdate(input: {
      id: "gid://shopify/Product/7482579091675", 
      metafields: [
        {
          namespace: "sf_product_track", 
          key: "expiry_date", 
          value: "2022-12-30", 
          type: "string"
        }
      ]
  }) {
    product {
      id,
      title,
      metafield(namespace: "sf_product_track", key: "expiry_date") {
        id
        namespace
        key
        value
        type
      }
    }
  	userErrors {
        field
        message
    }	
  } 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment