1. Home
  2. Developer tools
  3. GraphQL Formatter

GraphQL Formatter

Clean up a one-line query from a network log and check whether it will hit a server’s depth or cost limits before you ship it.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use GraphQL Formatter

  1. Paste a query, mutation or schema.
  2. Copy the formatted version.
  3. Read depth, fields and estimated cost per operation.

Features

  • Formatting with the reference graphql-js printer
  • Syntax errors with line and column
  • Depth, field and alias counts per operation
  • Cost multiplied by first, last and limit arguments
  • Unused fragments and alias-heavy queries flagged

Supported formats

Input

  • GRAPHQL
  • Typed or pasted text

You get

  • GRAPHQL

Private by design

Everything you enter is processed by your browser on this device. Nothing is sent to openWorkstand or anyone else, so the GraphQL Formatter is safe for private and work data. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • Checks syntax, not types: it does not validate a query against a schema.
  • Cost is an estimate; each server applies its own model.

Guide

Formatting GraphQL and estimating what a query costs

GraphQL queries are often copied from network logs, error reports and code generators on a single line, which makes them hard to read and review. And because one query can ask for nested lists of lists, a request that looks small can ask the server for thousands of objects. This tool formats queries, mutations and schemas with the reference printer and estimates the depth, size and cost of each operation.

Formatting with the reference printer

The text is parsed with graphql-js, the reference implementation maintained by the GraphQL Foundation, and printed back with its print function. That produces the canonical layout: two-space indentation, one field per line, arguments and variables formatted consistently and comments removed. If the text does not parse, the parser’s message with line and column appears instead, which is often the fastest way to find a missing brace.

Depth, fields and aliases

For each operation, the analyser counts how deeply selections are nested, how many fields are requested and how many aliases are used. Depth matters because many servers reject queries above a limit such as 7 or 10 levels to prevent deeply recursive requests. Fields inside fragments count where the fragment is spread, and introspection fields such as __typename are left out.

The cost model

Field counts understate the work when lists are involved. The estimate follows the approach public APIs such as GitHub’s use: every field costs 1, multiplied by the page size of each list it sits inside, read from arguments named first, last, limit, take, pageSize, perPage or count. A field inside repositories(first: 20) costs 20; inside issues(first: 5) within that, it costs 100. Lists without a size argument count as 1, so the real cost can be higher.

Fragments and warnings

Named fragments are expanded where they are spread, with protection against fragments that spread each other in a loop. The analyser warns about fragments that are defined but never used, operations deeper than seven levels, more than ten aliases in one operation, and documents with several operations where one is unnamed, which servers reject.

A worked example

The Sample is a one-line RepoDashboard query. After formatting it starts query RepoDashboard($owner: String!, $name: String!) { and spreads over several dozen lines. The analysis reports a depth of 7, 25 fields, no aliases and an estimated cost of 1,305. The comments alone account for 800 of it: up to ten comments for each of twenty issues, each with a body and an author login, even though the query names those fields only once.

Schemas too

Schema definition language (SDL), the type, interface, enum, input, union and scalar definitions in schema.graphql files, is formatted the same way, and the number of type definitions is reported. Cost analysis applies only to operations.

What a syntax-only analyser cannot know

The tool does not have your schema, so it cannot tell whether fields exist, whether arguments have the right types or whether a list returns ten items or ten thousand when no size argument is given. Each server has its own cost formula and limits; use this estimate to compare versions of a query and to spot the ones that multiply, then check the real numbers against the API’s documentation or its rate-limit headers.

Checked against the current version of the GraphQL Formatter on .

Frequently asked questions

Why do some APIs require first or last on every connection?

Without a page size, a list field could return millions of nodes, and nested lists multiply that. Requiring first or last lets the server compute the worst-case cost before running the query and reject expensive ones, which is how GitHub and Shopify keep their public APIs stable.

Are aliases dangerous?

Not in normal use; they rename fields and let you fetch the same field with different arguments. The risk is abuse: one query can repeat an expensive field hundreds of times under different aliases. Servers counter that with cost analysis or alias limits, which is why the analyser flags heavy alias use.

Why is the cost so much higher than the number of fields?

Nested lists multiply. Twenty repositories with ten issues each, each with five labels, asks the server for 20 × 10 × 5 = 1,000 label objects even though the query only names one label field.

Does it validate my query against a schema?

It checks syntax, not types. A query can be well-formed and still ask for fields the server does not have; run it against the API or validate with the schema in your editor.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.