GraphQL API Node Client Not Loading Referenced Metaobject Fields

joshandromidas
Shopify Partner
1 0 1

There seems to be a discrepancy between the Shopify GraphQL App which is configured in my store's Apps, and the GraphQL API client I'm using via Shopify's official library, specifically regarding fetching data from a product which has a metafield which references a metaobject. (Using LATEST_API_VERSION, ApiVersion.April23, but also reproducible in the January 23 version)


To show what I mean, in the Shopify GraphQL App which was installed in my store with read/write permissions for products, inventory, and metaobjects, I write the following query:

query AllProductsQuery {
  products(first: 80) {
    edges {
      node {
        id
        title
        metafield(key: "custom.my_field_name") {
          reference {
            ... on Metaobject {
              field(key: "custom_field_key") {
                value
              }
            }
          }
        }
        variants(first: 5) {
          edges {
            node {
              id
              title
              price
              weight
              weightUnit
            }
          }
        }
      }
    }
  }
}

And the app returns data that looks something like this:

{
  "data": {
    "products": {
      "edges": [
        {
          "node": {
            "id": "gid://shopify/Product/XXXXX",
            "title": "Product One Title",
            "metafield": {
              "reference": {
                "field": {
                  "value": "21"
                }
              }
            },
            "variants": {
              "edges": [
                {
                  "node": {
                    "id": "gid://shopify/ProductVariant/YYYYYY",
                    "title": "Default Title",
                    "price": "100.00",
                    "weight": 5,
                    "weightUnit": "GRAMS"
                  }
                }
              ]
            }
          }
        },
      // ... more nodes
    ]
  }
}

 

This is all fine, until I use this exact same query within the API client on my server:

const myProducts = await client.query({ data: AllProductsQuery });

… where `AllProductsQuery` is the copy/pasted, fully-functioning query from the GraphQL Playground App in my store.

 

The response I get when running the query in my code looks exactly the same as the return from above EXCEPT for the metafield reference, which returns `null`:

...
  "metafield": {
    "reference": null
  },
...


This is the exact same query, the exact same store, the exact same API version (April 23), and Shopify's official node client, which is the reason I'm inclined to believe it's an issue with Shopify's API. I really wish I'm wrong and that it's possible to retrieve the referenced metaobjects from a metafield with the GraphQL API.

 

I've tried with the REST API, but metafields don't seem to be supported at all, as returning all the data in the products doesn't return metafields at all. My end goal is just to retrieve the data indicated in the above GraphQL query in any (efficient) way possible.


Thanks!

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1357 224 473

Hi @joshandromidas , I am assuming you're app already has the `read_metaobjects` scope in place? https://shopify.dev/docs/api/admin-graphql/2023-01/queries/metaobjects#:~:text=Requires-,read_metaob...  If you continue to have issues retrieving Metafield data you could contact our Partner Support channel with details of your app and an x-request-id and timestamp for the failing call and we can investigate it specifically. Please note any examples should be within 14 days as this is the log retention period.  

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog