Metaobjects association

Topic summary

How to relate a metaobject to a product and use it in themes.

  • Association approach: Define a metaobject with a field of type “product_reference” in MetaobjectDefinition.fieldDefinitions. Then create a metaobject instance and set that field’s value to the target product’s GID (e.g., gid://shopify/Product/…).

  • Key terms: MetaobjectDefinition defines the schema (fields and types) for metaobjects. “product_reference” is a field type that stores a reference to a Product. GID is a global identifier used by Shopify APIs.

  • Implementation: Example GraphQL mutations and variable payloads were provided for metaobjectDefinitionCreate and metaobjectCreate to configure the product reference field and assign a product.

  • Theme access: Metaobjects are accessible via Admin API, Liquid, and Storefront API, enabling use within theme app extensions and storefronts (docs referenced).

  • Outcome: The original question about relating metaobjects to products was answered with concrete mutations and types. A follow-up on Liquid availability was also confirmed. No unresolved issues remain.

Summarized with AI on February 2. AI used: gpt-5.

I’m trying the new metaobjects api. After creating a metaobject definition and creating a metaobject is it possible to relation it to a product for example?

F.

Hi @Meltin-Bit :waving_hand:

When creating the metaobjectDefinition, we can set one of the MetaobjectDefinition.fieldDefinitions to hold a product reference by setting the MetafieldDefinitionType.name to “product_reference”. A full list of supported types can be found here.

Below is an example:

mutation ($input: MetaobjectDefinitionCreateInput!) {
    metaobjectDefinitionCreate(definition: $input) {
        metaobjectDefinition {
            id
            type
            fieldDefinitions {
                key
                name
                type {
                    name
                }
            }
        }
    }
}

With variables:

{
    "input" : {
        "type": "$app:product_related_metaobject",
        "access": {
            "admin": "MERCHANT_READ_WRITE",
            "storefront": "PUBLIC_READ"
        },
        "capabilities": {
            "publishable": {
                "enabled": true
            }
        },
        "fieldDefinitions": { 
            "key": "product", 
            "name": "Related Product", 
            "type": "product_reference" 
        }
    }
}

Then to create this product-related metaobject, we can use the ](https://shopify.dev/api/admin-graphql/2023-01/mutations/metaobjectCreate)[metaobjectCreate mutation as follows:

mutation($input: MetaobjectCreateInput!) {
    metaobjectCreate(metaobject: $input) {
        metaobject {
            id
            type 
            field(key: "product") { value }
        }
    }
}

With variables:

{
    "input" : {
        "type": "$app:product_related_metaobject",
        "fields": {
            "key": "product",
            "value": "gid://shopify/Product/6832753737846"
        }
    }
}

Hope that helps!

3 Likes

Thanks, this make sense :slightly_smiling_face: Do you know if metaobjects are available in liquid like metafields? Something like app.metaobjects…? This would be nice inside a theme app extension.

1 Like

Hey Meltin-Bit, great question!

The short answer is yes, metaobjects are available in themes using the Admin API, Liquid, and the Storefront API. This is mentioned in our overview doc here, which is a good place to get an idea of the feature. The doc also links our developer resources for each method of access, and some links to other guides on access, capabilities and metaobject management.

Cheers!

1 Like