Skip to content
ENExplore Calculators

GraphQL Query Complexity Calculator

Compute the depth × breadth cost of a GraphQL query, the resolver load it implies and whether your cost limit would reject it.

About GraphQL Query Complexity Calculator

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.

Formulas

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.

b
Fields selected per level
p
List items returned per level
d
Query depth
r
Branching factor b × p

Cost and load

total cost = nodes × cost per field × aliased copies; resolver time = nodes × copies × latency per node.

aliased copies
The same subtree repeated under different aliases in one request
cost per field
Static cost assigned to a resolved field

Worked example

With the default values below, GraphQL Query Complexity Calculator returns Query Cost of 7,541,379,300. Change any input above and every figure here is recalculated in your browser.

Inputs used

Query depthaccepts 1–30 levels
6 levels
Selected fields per levelaccepts 1–50 fields
3 fields
List items returned per levelaccepts 1–1,000 items
10 items
Cost units per resolved fieldaccepts 0.01–1,000 units
1 units
Aliased or batched copies per requestaccepts 1–1,000 copies
10 copies
Configured query cost limitaccepts 1–1,000,000,000 units
1,000 units
Resolver latency per nodeaccepts 0.001–1,000 ms
0.4 ms

Results

Query Cost
7,541,379,300 units
Nodes Resolved
754,137,930
Cost of One Copy
754,137,930 units
Resolver Time
3,016,551.72 seconds
Amplification vs a One-Field Query
7,541,379,300 ×
Cost Limit Decision
Rejected — the query exceeds the cost limit by 7541379×

Step by step

  1. 1Values used
  2. 2GraphQL Query Complexity
  3. 3Cost and load
  4. 4Query Cost= 7,541,379,300 units
  5. 5Nodes Resolved= 754,137,930
  6. 6Cost of One Copy= 754,137,930 units
  7. 7Resolver Time= 3,016,551.72 seconds
  8. 8Amplification vs a One-Field Query= 7,541,379,300 ×
  9. 9Cost Limit Decision= Rejected — the query exceeds the cost limit by 7541379×

Assumptions and limits

  • The result is derived only from the 7 inputs listed above. Anything not among them is not part of the calculation.
  • In particular, this calculator does not take inflation, tax or compounding frequency into account.
  • Figures are rounded for display to 2 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.

How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.

Frequently Asked Questions

How is GraphQL Query Complexity calculated?

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.

Why does GraphQL Query Complexity matter?

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.

What values do I need to enter?

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.

Is a depth limit enough on its own?

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.

GraphQL Query Complexity Calculator | Calcrivo