[Liquid] How can I access more than 50 metaobjects referenced to a product metafield?

I have the following metafield definition on my product as a custom data definition inside my app toml file.

[product.metafields.app.xxx]
name = "xxx"
description = "Reference to a xxx metaobject."
type = "list.metaobject_reference<$app:xxx>"
access.admin = "merchant_read"
access.storefront = "public_read"

But this allows me to access only the first 50 metaobjects in liquid of theme app extension.

How can I access more than 50 objects as it allows me to save more than 50 objects

This is how I am looping this object

{%- assign rubik_swatch_metafield = product.metafields["$app"].xxx -%}
{%- for swatch in rubik_swatch_metafield.value -%}

but this loop iterates only over first 50 objects

I haven’t tried it myself but maybe paginate ?

Unfortunately it is not possible to paginate only on all metaobjects of that type which is not efficient.

You’re hitting the Liquid for-loop cap. I can’t think of a clean solution for this, but here are two other options beyond what’s already been discussed:

  1. Storefront API. Query the metafield with JS in your extension.

  2. Restructure the data. The simplest approach is to split the references across multiple metafields with 50 or fewer items each, then loop through each one.

{%- for swatch in product.metafields.custom.rubik_swatch_metafield_0.value -%}
{%- endfor -%}
{%- for swatch in product.metafields.custom.rubik_swatch_metafield_50.value -%}
{%- endfor -%}
{%- for swatch in product.metafields.custom.rubik_swatch_metafield_100.value -%}
{%- endfor -%}

Thanks, @Paige-Shopify I was actually considering the second option, as it will be backward-compatibility-friendly. But it would be great if Shopify could introduce an official way to paginate over metaobject references for this case. Can you please create an internal feature request with the relevant team? :folded_hands: