[GraphQL] Cant get metafield for collection

[GraphQL] Cant get metafield for collection

lesliewong
Shopify Partner
8 0 1

Hello, I encounter a very strange case. Please help to check it.

I tried to get a specific metafield for customer & product using namespace & key:

query {
 customer(id: "gid://shopify/Customer/7283356106") {
   metafield(namespace: "test", key: "hello") {
     value
   }
 }
}

 

query {
  product(id: "gid://shopify/Product/3667578847316") {
    id
    metafield (namespace: "test", key: "test_key") {
      value
    }
  }
}

Both of them return result successfully, but when I try it for collection

query {
  collection(id: "gid://shopify/Collection/135688257620") {
    id
    metafields(first:10){
      edges{
        node{
         id
          namespace
          key
          value
        }
      }
    }    
    metafield (namespace: "test", key: "hello") {
      value
    }
  }
}

It failed to return the metafield value (as shown below, it is null). But I can see the records under metafields:

{
  "data": {
    "collection": {
      "id": "gid://shopify/Collection/135688257620",
      "metafields": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/Metafield/8257558773844",
              "namespace": "test",
              "key": "hello",
              "value": "sdasd"
            }
          }
        ]
      },
      "metafield": null
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 14,
      "actualQueryCost": 5,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 995,
        "restoreRate": 50
      }
    }
  }
}

I think it is a bug for collection, which I cant use namespace & key to find the metafield...

 

 

 

 

 

Replies 3 (3)

Josh
Shopify Staff
1134 84 235

Hi @lesliewong ! 

 

You're correct, this is a bug that we're currently investigating. It only affects collections for some reason, and even then it is only when trying to zero in on a specific metafield. If you were to change your query to look for multiple metafields (ex. metafields(first:20)) you'd be able to see the metafields that you're expecting. 

 

I don't have an ETA on a fix for this at the moment, but it is something that we're aware of and working to fix as we speak. 

Josh | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

lesliewong
Shopify Partner
8 0 1

Thanks @Josh , we have a program using this API call and it stop running 2 weeks ago, that why we noticed that. 

For sure we can use "metafields" instead of "metafield", hopefully it will be resolved very soon, since search by namespace & key is much more convenient than extract all metafields and loop through one by one. Thanks.

Josh
Shopify Staff
1134 84 235

Hello again @lesliewong ! 

 

Great news - the fix for this went out about ~14 hours or so ago and things should be working as expected again. Enjoy!

Josh | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog