Start a project

Tool 126 of 194 · API

GraphQL Query Complexity Analyser

Find out how expensive a GraphQL query is before it hits your server: validate it against the schema and see the cost of every field.

GraphQL Query Complexity Analyser

Schema (SDL)

Query

Cost and limits

    FieldTypeMultiplierWeightRepeatedCost

    Each field costs its weight plus its multiplier times the cost of its children. Multipliers come from slicing arguments (first, last, limit and similar, or those named in @listSize), then @listSize(assumedSize), then the assumed list size; edges and nodes inside a sliced connection aren't multiplied again. @cost(weight) overrides a field's weight. Fragments are expanded and @skip/@include honoured.

    01

    What it does

    Validates a GraphQL operation against your schema, then works out its depth, requested nodes and cost with list multipliers, @listSize and @cost.

    • Validation against your SDL: unknown fields and arguments, required arguments, leaf selections, fragments, variables and spreads
    • Depth and field count with fragments expanded and @skip/@include honoured
    • Cost with multipliers from first, last, limit and similar arguments, including their schema defaults
    • @listSize (assumedSize, slicingArguments) and @cost(weight) from the IBM GraphQL cost directive spec

    02

    Private by design

    Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

    03

    What you get

    Validation errors, depth, nodes, cost and a per-field cost table, with a Copy and a Download button on every result.

    • GraphQL
    • APIs
    • Performance
    • Security

    Why it matters

    A single GraphQL request can ask for a few fields or for millions of records: ten products, each with ten reviews, each by a customer with ten orders, is already a thousand rows. Servers protect themselves with depth limits and cost analysis, and clients hit those limits with errors that rarely say which part of the query is to blame.

    This analyser validates the query against your schema with the core GraphQL rules (checked against graphql-core, the Python port of the reference implementation), then walks it field by field. Every field gets a weight and a multiplier from its page-size argument, so the table shows exactly where the cost comes from and how far a smaller first would bring it down.

    How to use it

    1. Paste your schema in SDL.
    2. Paste the query, and any variables as JSON.
    3. Set the costs and limits your server uses.
    4. Read the validation errors, the totals and the cost of each field.

    FAQ

    How is GraphQL query cost calculated?

    Each field has a weight, and fields that return lists multiply the cost of everything below them by the number of items requested. Summing over the query gives its cost.

    What is query depth?

    The deepest level of nested fields. Depth limits stop recursive queries such as friends of friends of friends.

    What do @cost and @listSize do?

    They come from the IBM GraphQL cost directive spec: @cost sets a field's weight, and @listSize says how many items a list returns or which arguments set its size.

    Why is my list field assumed to return 10 items?

    Without a page-size argument or @listSize, its size is unknown, so an assumption is used. Change it under Cost and limits, or annotate the schema.

    Work with me

    Want a site that gets these right?

    I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

    All developer tools · Back to leej.uk