In Shopify using GraphQL how should I query a metaobject & a sub-query metaobject in a single query?

In Shopify using GraphQL how should I query a metaobject & a sub-query metaobject in a single query?

danabdn
Shopify Partner
16 0 6

I am building a website with Shopify Hydrogen.

 

Using GraphQL I am accessing MetaObjects.

 

The structure of the MetaObject is one field and one sub-MetaObject field (a generic, reusable meta object).

 

I wish to write a query that gives me the fields from the MetaObject (working) and the Sub-MetaObject (not working - only giving an id).

 

My query looks like this...

query {
    metaobject(        handle: {
            handle: "template-home",
            type: "header_template",
        }
    ) {
        handle,
        type
        page_url: field(key: "page-url") {
            value
        },
        header_info: field(key: "header_info") {
            value
        },    
    }
}

..and that gets half the job done but doesn't let me see the sub-metaobject and the result is...

{
    "data": {
        "metaobject": {
            "handle": "template-home",
            "type": "header_template",
            "page_url": {
                "value": "/"
            },
            "header_info": {
                "value": "gid://shopify/Metaobject/1234567890"
            }
        }
    }
}

I don't want the key/id to the Metaobject returned, I want the fields/data from the meta object as a sub-result (or even flattened in the parent would be fine too).

 

How do I write another sub-query to expose all the fields within this sub-meta object so I can run one command. 

 

If not possible, how do I best avoid multiple server calls to Shopify in Remix?

 

Thanks,

Dan.

Replies 2 (2)

Kumar2573
Shopify Partner
174 8 19

query {
metaobjects(type: "slider" first: 5){
edges{
node{
id
fields{
key
type
value
}
}
}
}
}

Shopify Certified Developer Profile - https://www.credly.com/badges/1733d05c-2a88-490a-aef5-b01baf3b94ce/public_url
Expert Shopify Plus & shopify Developer & Theme customizer
- If the problem is solved remember to click to Accept Solution
- Press Like ?? if the answer was helpful
- Still, Facing issue, Reach out to me Email :- jitendra3496@gmail.com | Skype :- jitendra2573_1
- Direct Hire me :- Direct Contact me

Kumar2573
Shopify Partner
174 8 19

query {
metaobjects(type: "tetx" first: 5){
edges{
node{
id
fields{
key
type
value
}
}
}
}
}

Shopify Certified Developer Profile - https://www.credly.com/badges/1733d05c-2a88-490a-aef5-b01baf3b94ce/public_url
Expert Shopify Plus & shopify Developer & Theme customizer
- If the problem is solved remember to click to Accept Solution
- Press Like ?? if the answer was helpful
- Still, Facing issue, Reach out to me Email :- jitendra3496@gmail.com | Skype :- jitendra2573_1
- Direct Hire me :- Direct Contact me