Conversion: Connections from a resource
{% for collection in product.collections %}
{% assign collection_tags = collection.tags | split: ", " %}
{% if collection_tags contains "my-tag" %}
{% log collection_with_my_tag: collection.title %}
{% endif %}
{% endfor %}{% assign cursor = nil %}
{% for n in (1..10) %}
{% capture query %}
query {
product(id: {{ product.admin_graphql_api_id | json }}) {
collections(
first: 250
after: {{ cursor | json }}
) {
pageInfo {
hasNextPage
endCursor
}
nodes {
id
title
tags
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"products": {
"nodes": [
{
"collections": {
"nodes": [
{
"id": "gid://shopify/Collection/1234567890",
"title": "Widget collection",
"tags": ["my-tag"]
}
]
}
}
]
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% for collection in result.data.product.collections.nodes %}
{% if collection.tags contains "my-tag" %}
{% log collection_with_my_tag: collection.title %}
{% endif %}
{% endfor %}
{% if result.data.products.pageInfo.hasNextPage %}
{% assign cursor = result.data.products.pageInfo.endCursor %}
{% else %}
{% break %}
{% endif %}
{% endfor %}PreviousConversion: Resource loops to paginated queriesNextConversion: Metafield lookups from a resource
Last updated
Was this helpful?