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!