We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Required solution on functions API Graphql query complexity limitation.

Required solution on functions API Graphql query complexity limitation.

John777
Shopify Partner
8 0 1
In product discount function API or any other functions API we have the limitation of 30 query complexity in Graphql input. Now In our app we need more than 30, as it is essential to our app's functionality. whenever we have complexity more than 30 we get this error message 
 
Error updating extension draft for product-discount: Query has complexity of 33, which exceeds max complexity of 30
 
I have tried several forum questions regarding this but, we required all the fields and other solutions like Metafield will not work for us. any help will be appreciated.
Replies 3 (3)

AUTHENTIC_TECH
Shopify Partner
3 0 1

Thanks for your message.

 

You're absolutely right in the product discount function API (and other function APIs), Shopify enforces a hard limit of 30 query complexity in the GraphQL input. When your query exceeds this (e.g. complexity of 33), it triggers the following error:

 

"Error updating extension draft for product-discount: Query has complexity of 33, which exceeds max complexity of 30."

 

Unfortunately, this limit is set by Shopify and cannot be increased.

 

Since you've noted that all fields are essential and Metafield-based solutions won’t work, here are your best options:

 

Optimize or split the query to stay within the limit

 

Offload logic to an external backend or App Proxy, then pass minimal required data to the function

 

Let me know if you need help restructuring the query or implementing one of these approaches.

 

Best regards.

John777
Shopify Partner
8 0 1

Thank you very much for the reply, and yes it would be really nice if you help me restructure the query or suggest me any different approach.
here is the whole query.

query RunInput(
  $lineItemProperty: String, 
  $startTime: TimeWithoutTimezone!, 
  $endTime: TimeWithoutTimezone!, 
  $collectionIds:[ID!],
  $customerTags: [String!], 
  $productTags: [String!],
  $cartAttributeKey: String
) {
  shop {
    localTime {
      timeBetween(endTime: $endTime, startTime: $startTime)
    }
  }
  cart {
    attribute(key: $cartAttributeKey) {
      key
      value
    }
    cost {
      subtotalAmount {
        currencyCode
        amount
      }
      totalAmount {
        amount
      }
    }
    lines {
      id
      quantity
      sellingPlanAllocation {
        sellingPlan {
          name
        }
      }
      cost {
        totalAmount {
          amount
        }
      }
      attribute(key: $lineItemProperty) {
        key
        value
      }
      merchandise {
        ...on ProductVariant {
          id
          product {
            id
            # productType
            inAnyCollection(ids: $collectionIds)
            hasAnyTag(tags: $productTags)
          }
        }
      }
    }
    buyerIdentity {
      purchasingCompany {
        company {
          name
        }
      }
      customer {
        hasAnyTag(tags: $customerTags)
        amountSpent {
          amount
        }
        email
        displayName
        numberOfOrders
      }
      isAuthenticated
    }
  }
  localization {
    country {
      isoCode
    }
    market {
      regions {
        name
      }
    }
  }
  presentmentCurrencyRate
  discountNode {
    metafield(namespace: "$app:product-discount", key: "function-configuration") {
      jsonValue
    }
  }
}
Abel_Lesle
Shopify Partner
367 8 25

Without knowing the use case in question, it'd be hard for anyone to help reduce your input query cost.

 

Please share further information so that someone can help you with optimising your function query.

Founder
Dollarlabs: Ultimate Discounts (5★) – If you can think of a discount, you can build it
Dollarback: Cashback & Loyalty (5★) – Simple cashback. Powerful loyalty.