πGraphQL in Liquid
Usage
{% capture query %}
query {
shop {
name
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% log result.data.shop.name %}{% assign cursor = nil %}
{% assign total_inventory = 0 %}
{% for n in (0..100) %}
{% capture query %}
query {
products(
first: 250
after: {{ cursor | json }}
) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
totalInventory
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"products": {
"edges": [
{
"node": {
"totalInventory": -4
}
}
]
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% for product_edge in result.data.products.edges %}
{% assign product = product_edge.node %}
{% assign total_inventory = total_inventory | plus: product.totalInventory %}
{% endfor %}
{% if result.data.products.pageInfo.hasNextPage %}
{% assign cursor = result.data.products.edges.last.cursor %}
{% else %}
{% break %}
{% endif %}
{% endfor %}Use GraphQL when...
Don't use GraphQL when...
Last updated
Was this helpful?