Query exceeds max complexity of 30

Solved

Query exceeds max complexity of 30

Maffle
Shopify Partner
6 0 0

I am developing an application for Shopify that applies automatic volume discounts based on the product metafileds and the tag the user has.
Everything works correctly, the problem is that when I enter all the metafileds and tags of interest I get this error.

 
Validation errors
targeting.0.input_query: Query has complexity of 31, which exceeds max complexity of 30

 

Many people recommend reducing the cost of the query but I don't know how to do it. Can you help me out?

query Input {

cart {
buyerIdentity {
email
customer{
hasTags(tags : ["star","vip"]){
hasTag
tag
}
}
}
lines {
id
quantity
cost{
prezzo: amountPerQuantity{
amount
}
prezzoDiConfronto: compareAtAmountPerQuantity{
amount
}

}
merchandise {
__typename
... on ProductVariant {
id
product {
star: metafield(namespace: "custom", key: "star") {
value
}
vip: metafield(namespace: "custom", key: "vip") {
value
}
dataStartvip: metafield(namespace: "custom", key: "datastart_vip") {
value
}
dataEndvip: metafield(namespace: "custom", key: "dataend_vip") {
value
}
dataStartstar: metafield(namespace: "custom", key: "datastart_star") {
value
}
dataEndstar: metafield(namespace: "custom", key: "dataend_star") {
value
}
}
}
}
}
}
discountNode {
metafield(namespace: "volume-discount", key: "function-configuration") {
value
}
}
shop {
localTime {
date
}
}
}
Accepted Solution (1)

tobebuilds
Shopify Partner
434 29 117

This is an accepted solution.

Each metafield you fetch adds 3 to your query complexity. I recommend storing a JSON object in a single metafield, rather than having 6 separate metafields on your product.

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

View solution in original post

Reply 1 (1)

tobebuilds
Shopify Partner
434 29 117

This is an accepted solution.

Each metafield you fetch adds 3 to your query complexity. I recommend storing a JSON object in a single metafield, rather than having 6 separate metafields on your product.

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