In order to use the metaobjectCreate mutation to add metaobject’s associated with a Shopify-internal taxonomy attribute’s like Country, for example, it requires a taxonomy_reference, which is a gid of type TaxonomyValue. If given some country name as input, for example Germany, how can I identify whether it exists in Shopify’s taxonomy already and if so, to retrieve its gid?
I have checked the metaobject and metaobjects queries, however these are scoped to the current store and do not allow querying of the taxonomy. I have seen that if I know the gid, I can load its details using the node query, but that doesn’t help here. The only way I’ve seen to provide a list of taxonomy values for a given attribute is by using the taxonomy query:
query {
categories(first: 10) {
nodes {
id
fullName
level
name
attributes(first: 10) {
nodes {
__typename
... on TaxonomyChoiceListAttribute {
id
name
values(first: 10) {
nodes {
id
name
}
}
}
}
}
}
}
}
If I go through the pagination enough I will eventually find the desired attribute and the first X (10 in this example) taxonomy values:
{
"__typename": "TaxonomyChoiceListAttribute",
"id": "gid://shopify/TaxonomyAttribute/2364",
"name": "Country",
"values": {
"nodes": [
{
"id": "gid://shopify/TaxonomyValue/8807",
"name": "Australia"
},
{
"id": "gid://shopify/TaxonomyValue/8808",
"name": "Austria"
},
...
However, this is a really inefficient, super nested query that requires paginating through all taxonomy values to determine if the desired value exists in the Shopify taxonomy before choosing “Other” by default.
Surely there must be a better way?
I have seen the admin interface using a query called SuggestedMetaobjects but this doesn’t seem to be available for app developers, despite being exactly what I need:
operationName=SuggestedMetaobjects
variables={"type":"shopify--country","first":20,"after":null,"displayName":"Germany"}
Results:
"suggestedMetaobjects": {
"edges": [
{
"cursor": "<removed>",
"node": {
"displayName": "Germany",
"title": "Germany",
"id": "gid://shopify/SuggestedMetaobject/3682",
"type": "shopify--country",
"fields": [
{
"key": "label",
"value": "Germany"
},
{
"key": "taxonomy_reference",
"value": "gid://shopify/TaxonomyValue/8815"
}
],
"handle": "germany",
"__typename": "SuggestedMetaobject"
},
"__typename": "SuggestedMetaobjectEdge"
}
],
"pageInfo": {
"hasPreviousPage": false,
"hasNextPage": false,
"__typename": "PageInfo"
},
"__typename": "SuggestedMetaobjectConnection"
}
Any ideas?