Compute the depth × breadth cost of a GraphQL query, the resolver load it implies and whether your cost limit would reject it.
Cost grows geometrically with depth because every level multiplies by the branching factor, which is why a depth limit alone is a blunt control and a cost limit is the real defence. Aliasing multiplies the whole subtree within a single request, so it is counted separately — that is the batching attack. One nested query on a schema with cyclic relationships can resolve millions of nodes, which is a self-inflicted denial of service that no rate limit catches because it is a single request.
GraphQL Query Complexity
A query selecting b fields per level over lists of p items branches by b × p at each of d levels, so nodes = Σ(b × p)^i for i = 1…d, a geometric series equal to r(r^d − 1) ÷ (r − 1) with r = b × p.
Cost and load
total cost = nodes × cost per field × aliased copies; resolver time = nodes × copies × latency per node.
A query selecting b fields per level over lists of p items branches by b × p at each of d levels, so nodes = Σ(b × p)^i for i = 1…d, a geometric series equal to r(r^d − 1) ÷ (r − 1) with r = b × p. Cost grows geometrically with depth because every level multiplies by the branching factor, which is why a depth limit alone is a blunt control and a cost limit is the real defence. Aliasing multiplies the whole subtree within a single request, so it is counted separately — that is the batching attack.
One nested query on a schema with cyclic relationships can resolve millions of nodes, which is a self-inflicted denial of service that no rate limit catches because it is a single request.
This calculator takes 7 inputs: Query depth, Selected fields per level, List items returned per level, Cost units per resolved field, Aliased or batched copies per request, Configured query cost limit, Resolver latency per node. The pre-filled defaults are a realistic starting point — replace them with figures from your own environment for a result you can act on.
No. A shallow query can still be enormous — a depth of three over three list fields of a thousand items each is a billion nodes — and a strict depth limit blocks legitimate nested queries. Assign static costs to fields, multiply by declared page sizes, reject over a budget, and cap aliases per request as well.