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 0 (0)