API Design Issue: Metaobject References

carhifi
Tourist
5 1 1
 
metaobject(handle: {
            handle: "dacia",
            type: "car-manufacturer"
            }) {
            fields {
                references(first: 250) {
                    nodes {
                        __typename
                        ... on Metaobject {
                            fields {
                                value
                            }
                        }
                    }
                }
            }
            

            
        }
 
This is my code.
 
As you probably now you can reference another metaobject from a metaobject field.
What I want to do is fetch all metaobject field references from a metaobject.
As this might be hard to understand:
 
I have some car manufacturer meta objects: Ford, Audi, Mercedes.
I also have some model meta objects: Audi A1, Ford MK3, Mercedes A-Class
Audi A1 references Audi in one metaobject field and so on...
Now I want to fetch all model metaobjects for e.g. Mercedes (Mercedes A-Class and so on...).
 
However, this seems impossible to me with the GraphQL API!

 https://shopify.dev/docs/api/storefront/2023-01/objects/Metaobject 

Inside the documentation of the Metaobject it reads that you cannot load references of MetaObjects.

 

In the Shopify Admin area however you can see up to ten references for each metaobject. Why isn't this part of the API? Are there workarounds?

 

Right now the only possible option seems to be to fetch all metaobjects and save them for a limited time on my PHP server to a MySQL database (where I can filter the data properly) and send only the required data as a reply to AJAX requests. But this is actually truly elaborate, I kinda expect the Shopify APIs to be able to deliver those data out of the box. What's your thoughts on this?

Reply 1 (1)

Gabe
Shopify Staff
18011 2848 4193

Hey @carhifi 

 

We were chatting here about this and based on the documentation, it seems that you are correct that the Shopify GraphQL API does not currently support loading references of metaobjects.

One potential workaround could be to use a different API that provides more advanced querying capabilities, such as the Shopify Admin API. However, this would require additional setup and configuration on your part. Again I'm no expert but hope you will find a solution for your car parts shop if the previously linked apps cannot help you!

 

Best,

Gabe | Social Care @ Shopify
 - War meine Antwort hilfreich? Klicke Like um es mich wissen zu lassen! 
 - Wurde deine Frage beantwortet? Markiere es als Akzeptierte Lösung 
 - Um mehr zu erfahren, besuche das Shopify Help Center oder den Shopify Blog