The documentation says:
MetafieldReference> Returns a reference object if the metafield definition’s type is a resource reference.
but if type is collection_reference the reference is always null.
I want my articles to have the same background color saved in the referenced collection’s metafields. This should be possible by traversing the graph based on the documentation. This is my query:
fragment ArticleCore on Article {
id
handle
title
content
tags
blog {
id
handle
}
collection: metafield(namespace: "custom", key: "related_collection") {
id
type
reference {
__typename
}
}
}
and this is the response:
{
"id": "gid://shopify/Article/596103856243",
"handle": "test-article-1",
"title": "Test Article 1",
"content": "lorem ipsum",
"tags": [
"cotton",
"summer",
"vintage"
],
"blog": {
"id": "gid://shopify/Blog/80360636531",
"handle": "news",
"__typename": "Blog"
},
"blocks": {
"id": "gid://shopify/Metafield/20625132814451",
"namespace": "custom",
"key": "blocks",
"description": null,
"type": "json",
"value": "{}",
"__typename": "Metafield"
},
"collection": {
"type": "collection_reference",
"reference": null, // should not be null...
"__typename": "Metafield"
},
"__typename": "Article"
}
This query should work on the API but it doesn’t work because reference union is GenericFile | MediaImage | Page | Product | ProductVariant | Video
fragment ArticleCore on Article {
id
handle
title
content
tags
blog {
id
handle
}
collection: metafield(namespace: "custom", key: "related_collection") {
id
type
reference {
__typename
... on Collection {
color: metafield(namespace: "custom", key: "color") {
value
}
}
}
}
}