DevTools Logo

GraphQL Depth & Complexity Analyzer

GraphQL Depth & Complexity Analyzer

Measure real query depth, node count and weighted cost — then get safe depth-limit and cost-cap settings.

Runs in your browser
Try an example

GraphQL document

Analysis settings

Field weights

Use Type.field or a plain field name. Default weight: 1.

Thresholds (CI verdict)

Cost analysis

Paste a GraphQL query to measure its cost

Results update locally as you type. Nothing leaves your browser.

Details

Paste a GraphQL operation to see its maximum nesting depth, total field-node count and a transparent complexity score. Named fragments are unfolded with a cycle guard, aliases are charged separately, and list multipliers apply to entire subtrees. Add field weights, a variables payload or an SDL schema to match your production cost model, then copy the suggested graphql-depth-limit and graphql-cost-analysis configuration. Nothing is executed or uploaded.

More examples

Nested list cost

Input:
{ users(first: 10) { id friends(first: 2) { id } } }

Output:
Depth 3 · Nodes 4 · Complexity 60

The nested list is multiplied through the whole subtree: (1 + 1 + (2 × 2)) × 10 = 60.

Fragments unfolded at each spread

Input:
{ a { ...F } b { ...F } }
fragment F on User { id name }

Output:
Depth 2 · Nodes 6 · Complexity 6 · F used 2×

Each spread site is charged independently, matching how a server executes the document.

SDL-aware list detection

SDL:
type Query { users: [User!]! }
type User { id: ID! }

Query:
{ users { id } }

Output:
Complexity 20 (list × 10)

With a schema, list-ness is exact even when the query has no pagination arguments.

Fragment cycle

Input:
fragment A on User { ...B }
fragment B on User { ...A }

Output:
Fragment cycle: A → B → A

Cyclic fragments are blocked before any cost numbers are reported.

    Examples

    Nested lists

    Input
    { users(first: 10) { id friends(first: 2) { id } } }
    Output
    Depth 3 · Nodes 4 · Complexity 60

    The inner list's cost is multiplied again by the outer list: (1 + 1 + (2 × 2)) × 10 = 60.

    Fragment spreads

    Input
    { a { ...F } b { ...F } }
    fragment F on User { id name }
    Output
    Depth 2 · Nodes 6 · Complexity 6 · F used 2×

    Each spread site is charged independently, which is how servers execute the document.

    SDL-aware list

    Input
    SDL: type Query { users: [User!]! }
    Query: { users { id } }
    Output
    Complexity 20 — list × 10

    Without SDL there is no pagination argument, so the heuristic would report 2 instead.

    Cycle detection

    Input
    fragment A on User { ...B }
    fragment B on User { ...A }
    Output
    Fragment cycle: A → B → A

    Analysis is blocked and the cycle path is shown instead of silently wrong metrics.

    About this tool

    Public GraphQL endpoints need depth and complexity limits, but picking numbers by guesswork either breaks legitimate clients or leaves a denial-of-service surface open. This analyzer parses your operation, unfolds fragments with a cycle guard, and reports the maximum field nesting, the total field-node count and a transparent complexity score.

    The cost model is deliberately explicit: a field costs (its weight plus the cost of all child fields) multiplied by its list multiplier, so a list nested inside another list is charged through both levels. Aliases are separate fields, directives are counted as present for worst-case safety, and variable list arguments use a default multiplier unless you supply their real values.

    You can paste an SDL schema for exact list-ness and type-aware weights, set field weights such as User.name: 3, and enter pass/fail thresholds for CI. The recommendation panel emits a graphql-depth-limit call and a graphql-cost-analysis configuration that are always above the observed query, so the query you just measured is not rejected by its own suggested limit.

    Everything runs in the browser tab. Queries and schemas reveal API shapes, so they are never uploaded, and no operation is executed.

    What this tool does not do

    • This is static analysis: no schema validation beyond fragment checks, no resolver timings and no query execution.
    • Without SDL, list-ness is a heuristic based on first/last/limit/after/before arguments.
    • The depth convention is configurable because libraries disagree on how inline fragments and spreads count; match the toggle to your server library.
    • Directive conditions are always counted as present, so the score is a worst case, not a prediction of one request.
    • Documents over 1 MB or with more than 200,000 selections are rejected to keep the browser responsive.
    • Threshold verdicts are advisory and do not enforce anything on a server.

    How to use this tool

    1. Paste an operation

      Type or paste a query, mutation or subscription; analysis updates as you type and supports multiple named operations.

    2. Choose the counting rules

      Toggle fragment unfolding and inline-fragment depth levels to match the library your server uses.

    3. Refine the cost model

      Add field weights, a variables payload or an SDL schema under Analysis settings, and change the default list size.

    4. Read the tables

      Check the summary cards, the root-field table sorted by cost, the fragment inventory and the expandable per-field breakdown.

    5. Copy the limits

      Copy the suggested depth-limit and cost-analysis snippets, or download the JSON or Markdown report for a ticket.

    Use cases

    Choose production limits

    Measure your real client queries and pick a depth limit and complexity cap that are above legitimate traffic but below abuse patterns.

    Investigate a heavy client

    Sort root fields by cost and expand the per-field breakdown to find the branch that dominates a query.

    CI budget checks

    Enter thresholds and use the PASS/FAIL verdict badges as an advisory gate for new persisted queries.

    Calibrate a cost model

    Compare heuristic and schema-aware results, then tune field weights and default list sizes to match resolver cost.

    Counting conventions and inputs

    SettingEffect
    Unfold fragmentsOn: each spread site is charged like the fragment's fields in place. Off: the spread is one leaf node and adds no depth.
    Count inline fragmentsOn (default): an inline fragment selection set adds a depth level. Off: it is transparent, like a plain grouping.
    Default list sizeMultiplier used when a list has no numeric pagination argument; 10 by default.
    Variables JSONSupplies real values for first: $limit style arguments so they are not approximations.
    SDL schemaSwitches to schema-aware mode: exact list types, field types and Type.field weight keys.
    ThresholdsMaximum depth, complexity and aliases; produces PASS/FAIL badges for CI use.

    Complexity of a node = (weight + sum of child costs) × list multiplier; aliases are charged individually.

    Common mistakes

    Mistake:Setting a depth limit below the depth of legitimate queries.

    Fix:The suggested band is always at least two levels above the deepest observed operation; if your query exceeds the usual 15-level band, reduce nesting first.

    Mistake:Assuming a list multiplier only applies to the list field's own weight.

    Fix:This tool multiplies the entire subtree under the list, which is what makes nested pagination expensive in real endpoints.

    Mistake:Deriving a complexity cap from a single root field.

    Fix:The recommendation uses the total cost across the operation, so multiple root fields can still fit under the cap.

    Mistake:Treating a variable pagination argument as an exact cost.

    Fix:Supply the variables payload; otherwise the tool uses the default list size and flags the multiplier as variable-dependent.

    Mistake:Using heuristic list detection for a schema you actually know.

    Fix:Paste your SDL: exact list-ness and Type.field weights remove most of the approximation.

    Frequently asked questions

    What depth should I limit GraphQL queries to?

    Start from the deepest query your legitimate clients actually send, then set the limit at least two levels above it. The analyzer suggests a 5, 10 or 15 band for normal queries and explicitly warns when a query is deeper than those bands — a limit below the query you measured would reject your own client. Combine a depth limit with a complexity cap because a shallow query can still request thousands of fields.

    How is GraphQL complexity calculated?

    Each field has a weight (1 by default) and may have a list multiplier. This tool computes (weight + the cost of all child fields) × the list multiplier, so nested lists are multiplied through every level. Aliases count as separate fields, fragments are charged at every spread site, and you can override any weight with a Type.field or field-name entry in the settings.

    Do fragments count as depth?

    It depends on the library, so the analyzer supports both conventions. With Unfold fragments on (the default), a spread contributes the depth of the fragment's fields at the spread site and every spread is charged. With it off, the spread is a single leaf that adds no depth. Inline fragments add a level by default and can be made transparent with the second toggle.

    What are list multipliers?

    A list multiplier estimates how many items a list field returns. Numeric first, last or limit arguments give an exact multiplier, variables need their real values supplied as JSON, and everything else uses the editable default (10) or a per-type default. Pasting an SDL schema removes the guesswork because list-ness comes from the field type.

    Which libraries implement these limits?

    graphql-depth-limit enforces maximum nesting, and graphql-cost-analysis (or a custom complexity rule in graphql-js validation) enforces a cost budget. The recommendation panel emits ready-to-adapt snippets for both; verify the option names against the version your server uses before deploying.

    Does the analyzer execute or upload my query?

    No. Parsing, fragment unfolding, cost calculation and report export all happen in this browser tab. No operation reaches a server and no schema or query is stored in the cloud, which matters because both reveal private API shapes.

    References & standards