GraphQL Formatter

Beautify GraphQL SDL with two-space indentation, one field per line, and descriptions kept above their type

Input

Output

Paste your input on the left and the result shows up here.

Or drop a file on this box, , or .

What is the GraphQL Formatter?

Codegen output, a federation composer dump, or SDL pasted out of a chat thread rarely arrives with sane whitespace. You get type Order{id:ID! placedAt:DateTime!} on one line, enum values packed together, and a description glued to the next keyword. The GraphQL schema definition language is supposed to be the contract both teams read, so it should look like one. Drop the SDL into Input and the Output pane rewrites it with two-space indents, a line per field, arguments left on the field line, and each """ description sitting directly above the definition it documents.

Under the hood is a small tokenizer written for this page rather than the full graphql package, which keeps the bundle light. It splits the source into names, punctuation, strings, comments and block strings, tracks brace depth, and prints each token back with the spacing the October 2021 GraphQL spec uses in its own examples. That covers type, interface, union, enum, input, scalar, extend, schema and directive definitions, [Foo!]! modifiers, default values and directive applications. Feed the output back in and you get the same text again, which is what makes it usable as a pre-commit check.

The formatting happens locally in the page, so your schema never travels to a server and is not stored anywhere. Paste, beautify, copy.

How to Use the GraphQL Formatter

The page reformats as you type, so there are only three things to do: get the SDL in, read it, take it out.

1

Paste, Upload, or Load a Sample

Paste SDL into the Input pane and pause. The formatter waits 300 ms after the last keystroke and then reruns, and that delay is why the page has no Convert button. Upload reads a .graphql, .graphqls, .gql or .txt file, and Sample drops in a one-line storefront schema (Order, OrderItem, Customer, Money and two enums) so you can watch it unfold. A cramped shipping schema like this is a typical starting point:

type Shipment{id:ID! trackingNumber:String carrier:Carrier! parcels:[Parcel!]! shippedAt:DateTime} type Parcel{weightGrams:Int! label:String} enum Carrier{DHL UPS ROYAL_MAIL}

A subgraph file that adds fields through extend type Query is laid out the same way as a plain list of types, since the tokenizer does not care which server will load it. SDL that Apollo Server reads at startup formats here without any changes on your side.

2

Read the Beautified Output

The right Output panel renders the beautified SDL with two-space indentation. Each field, enum value, and union member gets its own line. Arguments stay inline on the field line so signatures read naturally. Descriptions written as block strings ("""...""") are kept above the type or field they describe, which is how the GraphQL specification recommends documenting a schema. If the SDL has unbalanced braces or any other parse error, the formatter surfaces a friendly inline message: it never throws or crashes.

3

Copy or Download

Once the Output pane looks right, Copy puts it on the clipboard for a PR comment or a wiki page, and Download writes it to schema.graphql. Clear empties the Input pane when you want to try a different file. None of these steps talk to a server.

When You'd Actually Use This

PR Review Readability

A teammate opens a PR that adds five new types to your schema. The diff looks like one giant block because the codegen output stripped formatting. Run the file through the formatter, then drop the beautified version into the PR description so reviewers can actually read what is being added. Following GraphQL schema best practices is much easier when reviewers can see the structure.

Schema Registry Diffs

Most schema registries (Apollo Studio, GraphQL Hive, Hasura) show diffs as line-by-line text. If one revision was minified and the next was pretty, every line shows as changed and the real change vanishes in the noise. Beautify both versions before uploading: same formatter, same output, real diff.

Docs and Onboarding

Writing public docs for a GraphQL API or onboarding a new engineer? Paste the schema in, copy the formatted version into the wiki or README. A schema with descriptions visible above each type is a much friendlier starting point than the unformatted blob the codegen tool spat out.

Pre-commit and CI Gates

Because the formatter is idempotent, you can run it as a pre-commit hook or a CI check: format the schema, fail the build if the result differs from the committed file. No more whitespace drift between contributors, and no more PRs where half the diff is reformatting noise.

Common Questions

Does it validate my schema, or just format it?

Formatting only. It stops on an unclosed { or an unterminated string, because it cannot lay those out, and tells you the line. A field typed as Custmer when the type is called Customer sails straight through. To catch that kind of mistake, load the schema with buildSchema from the reference graphql-js package or let your server fail at boot.

Is my schema sent to a server?

It stays in the tab. The tokenizer and printer are plain TypeScript bundled with the page, so the SDL is never posted anywhere and nothing is kept once you close the tab. A pre-release schema with unannounced types is fine to paste.

Does it handle block-string descriptions?

Yes. Triple-quoted descriptions ("""An order placed by a customer.""") are preserved and emitted on the line above the type or field they document. This is the canonical way to write SDL documentation per the GraphQL spec.

What about directives and custom scalars?

Both are kept. @deprecated, @key, and any custom directive stay inline on the field. Custom scalars like scalar DateTime are emitted as their own line. The formatter does not try to interpret directive semantics: that is up to your server.

Will already-formatted SDL get re-formatted?

It is idempotent: beautifying already-beautified SDL produces the same output. So you can run the formatter in a CI check or a paste-and-compare workflow without worrying about whitespace drift.

How big a schema can I paste?

This page sets no size limit. Formatting is a single pass over the tokens, so a large supergraph is fine; once a file reaches several megabytes, the editor redrawing all those lines is what slows down first.

Other GraphQL Tools

Same schema, different job: the GraphQL Viewer for reading one, and formatters for the JSON, XML and YAML files that usually sit beside it in a repo: