How to resolve query complexity issue in volume discount app development?

How to resolve query complexity issue in volume discount app development?

CCLH
Shopify Partner
3 0 1

I am developing an app for Shopify that applies automatic volume discounts based on the product metafields. For this, I obtain the shopping cart lines and obtain all the metafields that specify the discount breakpoints. Everything works correctly, the problem is that when requesting all the metafields I am exceeding the query.

Version couldn't be created.
product-discount
Validation errors
 • targeting.0.input_query: Query has complexity of 57, which exceeds max complexity of 30

 

 

query RunInput {
  cart {
    lines {
      quantity
      cost {
        amountPerQuantity {
          amount
        }
      }
      merchandise {
        __typename
        ... on ProductVariant {
          id
          product {
            id
            compra10: metafield(namespace: "producto", key: "compra_10") {
              value
            }
            compra12: metafield(namespace: "producto", key: "compra_12") {
              value
            }
            compra20: metafield(namespace: "producto", key: "compra_20") {
              value
            }
            compra25: metafield(namespace: "producto", key: "compra_25") {
              value
            }
            compra30: metafield(namespace: "producto", key: "compra_30") {
              value
            }
            compra50: metafield(namespace: "producto", key: "compra_50") {
              value
            }
            compra60: metafield(namespace: "producto", key: "compra_60") {
              value
            }
            compra100: metafield(namespace: "producto", key: "compra_100") {
              value
            }
            compra150: metafield(namespace: "producto", key: "compra_150") {
              value
            }
            compra200: metafield(namespace: "producto", key: "compra_200") {
              value
            }
            compra250: metafield(namespace: "producto", key: "compra_250") {
              value
            }
            compra300: metafield(namespace: "producto", key: "compra_300") {
              value
            }
            compra400: metafield(namespace: "producto", key: "compra_400") {
              value
            }
            compra500: metafield(namespace: "producto", key: "compra_500") {
              value
            }
            compra600: metafield(namespace: "producto", key: "compra_600") {
              value
            }
            compra1000: metafield(namespace: "producto", key: "compra_1000") {
              value
            }
            compra1200: metafield(namespace: "producto", key: "compra_1200") {
              value
            }
          }
        }
      }
    }
  }
}

 

 

Reply 1 (1)

tobebuilds
Shopify Partner
447 32 120

From the Shopify Functions docs: "Function input queries can have a maximum calculated query cost of 30."

 

This article contains a table that explains all the query field costs:

 

https://shopify.dev/docs/apps/functions/input-output#limitations

Founder, Regios Discounts app (4.9 stars, 54 reviews)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer