I’m using a demo development store to work on some discounting functions. I’d like to use shop metafields to hold discounting config that the functions can use.
The demo store has a pre-set metafield, with the key ‘alpine_sports’ - this is returned if I use the query
query testShopMetafields {
shop {
metafields(first:1) {
nodes {
type
id
key
value
}
}
}
}
{
"data": {
"shop": {
"metafields": {
"nodes": [
{
"type": "list.single_line_text_field",
"id": "gid://shopify/Metafield/48202321953112",
"key": "alpine_sports",
"value": "[\"snowboarding\"]"
}
]
}
}
},
However, if I use a direct query using the key
query testShopMetafields {
shop {
metafield(key: "alpine_sports") {
type
id
key
value
}
}
}
It returns nothing:
{
"data": {
"shop": {
"metafield": null
}
}
Is this expected behaviour? If so, why? I have found that it also applies in the reverse; that is, if I create a metafield on the shop I can directly query it, but it isn’t listed as one of the shop’s metafields in the ‘metafields’ collection query response.
I’m guessing there are perhaps some permissions and scope issues at play, but for these two queries to have such different results is confusing, to say the least.