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

Topic summary

A developer is building a Shopify volume discount app that reads discount breakpoints from product metafields. The app retrieves cart lines and associated metafields to apply automatic discounts.

Core Problem:

  • The GraphQL query exceeds Shopify’s complexity limit (57/30 maximum)
  • The query requests 17 individual metafields per product (compra_10 through compra_1200)
  • Shopify Functions enforce a maximum calculated query cost of 30

Current Status:

  • The functionality works correctly aside from the query complexity constraint
  • One participant referenced Shopify’s documentation explaining query field costs and limitations
  • Discussion includes questions about how existing apps (like SupaEasy) handle multiple function inputs, though no solution was provided

Unresolved Questions:

  • How to restructure the query to stay within complexity limits
  • Whether other apps use the same input query across all merchants
  • No concrete solutions or workarounds have been shared yet
Summarized with AI on October 25. AI used: claude-sonnet-4-5-20250929.

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
            }
          }
        }
      }
    }
  }
}

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

@tobebuilds Do you know how this app SupaEasy: AI Functions creator - SupaEasy: migrate scripts and generate Functions with AI | Shopify App Store is able to manage different input for different functions… becuase i am able to use only 1 input QL

I don’t know. You might want to ask their team.

Also, if you have a moment, please upvote this GitHub discussion: Can the input query complexity be dynamic based on actual input values? · Shopify/function-examples · Discussion #566 · GitHub

@tobebuilds do you also use same input QL for all merchants on your discount app too??