GraphQL Query Depth Calculator for API Risk

July 22, 2026

GraphQL Query Depth Calculator

Estimate query depth score, complexity, resolver calls, and policy warnings from nesting, fanout, resolver cost, auth checks, pagination, and cache hit rate.

⚙GraphQL Presets
The model is intentionally conservative: nested lists compound resolver work, pagination reduces fanout, cache hits reduce effective calls, and auth multipliers represent permission checks, tenant filters, or policy middleware.
▣Query Shape Inputs
Top-level fields such as viewer, orders, products, or search.
Count object levels from root to deepest selected field.
Expected items per list after filters, not database table size.
Example: users → posts → comments equals two nested list edges below users.
Use 1 for scalar or dataloader cache, 10+ for DB/API heavy fields.
Higher for row-level security, tenant scopes, or per-node ACLs.
▤Policy and Runtime Controls
Common public GraphQL APIs cap depth around 6 to 10.
Set to the request budget used by your validation rule or gateway.
The server-side first/limit cap used for each connection.
Effective hit rate from DataLoader, resolver cache, CDN, or persisted query cache.
Selected leaf fields such as name, id, status, price, or timestamps.
Adjusts warning language and expected mitigation strategy.
Query Depth Score
0
Not calculated
Complexity Estimate
0
Cost units
Resolver Calls
0
Effective calls
Policy Warning
OK
Within policy
Run the calculator to see depth and complexity guidance.
Raw potential object nodes0
Effective fanout after pagination0
Cache reduction applied0%
Auth-adjusted cost0
Recommended actionCalculate
■Quick Risk Benchmarks
1-3
Low depth
Usually safe for public profile and lookup queries.
4-6
Normal app
Good target for product pages, feeds, and dashboards.
7-9
Review
Needs cost weighting, pagination, caching, and observability.
10+
High risk
Often blocked unless internal, persisted, or heavily bounded.
▦Complexity Strategy Grid
StrategyBest ForRisk ControlledImplementation Note
Depth limitPublic APIsRecursive object treesReject above max depth during validation.
Field cost mapMixed resolver costExpensive fields hiding in shallow queriesAssign weights to search, joins, and remote calls.
Connection multiplierList-heavy schemasFanout explosionMultiply child cost by first/limit caps.
Persisted queriesMobile and edge trafficUnknown ad hoc operationsAllowlist known operation hashes.
Rate plus complexityMulti-tenant APIsRepeated heavy requestsCharge request units, not only request count.
Resolver batchingN+1 prone schemasDatabase round tripsUse DataLoader or batch keys per request.
▥GraphQL Preset Reference
PresetTypical ShapePrimary RiskGood Policy
Viewer Profileviewer → orgs → teamsModerate auth checksDepth 5, cost 3000
Social Feedfeed → author → commentsNested connection fanoutDepth 6, page 25
Product Catalogproducts → variants → reviewsSearch plus list filtersCost map for search fields
Admin Dashboardaccounts → users → eventsTenant ACL checksAdmin-only persisted queries
Bulk Exportorders → items → shipmentsHuge list traversalAsync job instead of query
Abuse Probeself-referential fragmentsDepth and fanout bombBlock at validation
▧Depth and Cost Bands
BandDepth ScoreComplexitySuggested Response
Green1 to 30Under 1,000Allow, log sampled timings.
Blue31 to 701,000 to 5,000Allow with pagination and cache checks.
Yellow71 to 1205,000 to 15,000Warn, require review for public clients.
Orange121 to 20015,000 to 50,000Throttle or require persisted query.
RedOver 200Over 50,000Reject or run as controlled background work.
◇Practical Tips
Cap every list. A depth limit alone does not stop a shallow query that asks for thousands of list items.
Use weighted fields. A remote search resolver should cost more than a cached scalar field.
Batch resolvers. DataLoader-style batching can turn thousands of per-node lookups into a few grouped calls.
Separate exports. If a query is really a report or export, move it to an async job with its own limits.
Formula summary: depth score = depth × root fields × fanout pressure × auth multiplier. Complexity = object nodes × scalar fields × resolver cost × auth multiplier × cache miss rate. Resolver calls = object nodes × resolver cost × cache miss rate.

The flexibility of GraphQL makes it powerful, but it comes at the price of potential abuse. By asking for exactly what they want on the frontend, developer get full access to system. Leave the system open and you might be making thousands of database calls with one request. Your server will crash before anyone even notices the traffic spike.

Calculating the risk of queries is critical to securing an API. It’s not just about syntax. You’re predicting the cost of an operation before it occurs. To put it simply, the calculator will help you estimate the risk of a given query, by showing you what happens when that query gets loaded up.

How to Protect Your GraphQL API

Not only does it look at depth of the query. But depth is only part of the story. Often the issue is fanout. A query may be only 3 levels deep, for example. But if a second lookup is triggered by every item in one of those levels, your work are multiplied by a factor of one hundred. And that’s where developers get tripped up; they see a small number and think, “Oh yeah, I’m safe.” That is an illusion that the tool will expose.

You have to input realistic fanout values. And it lets you see what happens as you nest lists into lists, multiplying the number of resolver calls.

The answer lies in understanding what goes into your queries. By changing the resolver cost weight you are telling us that different fields aren’t created equal. It’s inexpensive to fetch a user’s name off a cached object graph. But a full text search? A call out to an external payment gateway? That’s expensive. Assign them higher cost values.

Why? Because a simple looking query could be shallow but have one very costly field. If we don’t consider this, the query will go unnoticed.

You’ll also see authentication multipliers that include the cost of checking permissions on each node. Because… security costs time. Each permission check introduces latency. And if you’ve got thousands of nodes, those milliseconds becomes seconds of waiting time.

Policy controls are safety nets. In most mature GraphQL APIs, there’s some sort of maximum depth limit (typically somewhere between six and ten levels). That’s an arbitrary-but-effective wall that prevents infinite recursions. With the tool, you can test your queries against those policy limits to see when they move from being acceptable to being blocked.

But it doesn’t end with depth. Pagination matters just as much. If you allow a client to ask for all items in a given list, then your depth limits won’t save you. You can still have a flat query that asks for ten thousand records which will crush your database. To reflect this, the calculator has pagination caps that demonstrate how limiting the size of lists limits effective fanout and thus keeps resolver calls under control.

Another source of relief is cache hit rates. Many of your resolver calls will be duplicates if your backend employs some form of batch mechanism like DataLoader. You can estimate this in the tool by entering the percent of requests that should hit the cache. This reduces the expected load on resolvers considerabley. That’s the point… A high-risk query can become a low-risk query with good caching.

Decisions made about your back-end directly impact the strength of your API. You can’t simply write policy in a vacuum, it needs to align with how data is cached and how it’s ultimately fetched.

On the page, there are reference tables with benchmarks for various kinds of queries. You want tighter limits on public APIs than you do on internal admin dashboards; those requests can be better controlled and more trusted. For example, you may want to block some kind of query from your mobile app but allow it for a backend reporting job. Policy depends on context. Don’t try to block everything. Only the requests whose cost exceeds their value (or exceed what you can handle).

Should of been blocked.

The solution is that visibility is the key to managing GraphQL complexity. What do your queries do? If you don’t know, then you won’t know until after they run. Running these simulations shifts your response mode from reactive to proactive. You begin to see how data flows through queries and where you might encounter bottlenecks or other issues. Suddenly this becomes an engineering challenge, rather than a potential disaster.

It’s not complicated math but it carries very real consequences if ignored. A bit of foresight keeps your API fast, secure and resilient to malicious probes as well as honest mistakes.

GraphQL Query Depth Calculator for API Risk

Related posts

Leave a Comment