GALAXY OF TOOLS

DEV SECTOR

GraphQL Formatter & Minifier

Format or minify GraphQL queries, mutations, fragments and SDL, check brackets, and build a cURL request.

Output

  

Document summary

KindNameDetails

Send it: request body, cURL or fetch

Query text

  

Parsed by a small GraphQL tokenizer in your browser — nothing is sent anywhere. It checks syntax structure (brackets, strings, characters), not your schema’s types.

Runs entirely in your browser. Nothing you enter or upload is sent to a server.

Format, minify and check GraphQL in one place

Queries copied from logs, network tabs or code are often one long line. This GraphQL formatter rewrites them in the canonical layout used by the reference GraphQL implementation: one field per line, nested selections indented, arguments separated by , , input objects kept inline ({field: CREATED_AT, direction: DESC}) and a blank line between definitions. It handles queries, mutations, subscriptions, fragments and inline fragments, directives, variables with default values, and schema definitions (SDL) — types, interfaces, enums, unions, inputs, scalars, descriptions and implements A & B.

The minifier strips comments, commas and whitespace while keeping the document valid, which is useful for persisted queries and smaller request bodies. A structural check reports unbalanced brackets, unterminated strings and stray characters with their line and column, and a summary lists each operation with its variables, every fragment and every type. Finally, choose an operation to get a ready JSON request body, a cURL command or a fetch call with placeholder variables.

The tokenizer and printer run in your browser; your queries and schema stay on your device.

How to use the GraphQL Formatter

  1. Paste a query, mutation, fragment or schema into GraphQL, or load one of the samples.
  2. Press Format for readable output or Minify for the compact form. Choose 2 spaces, 4 spaces or tabs, and whether to keep # comments.
  3. If an error appears, fix the bracket or string at the reported line and column.
  4. Check the Document summary for operations, variables, fragments and types.
  5. Under Send it, enter your endpoint, pick the operation, edit the variables JSON and copy the JSON body, cURL command or fetch snippet.

GraphQL Formatter features

Canonical formatting

Output matches the style of graphql-js print() — the same layout used by GraphiQL and most GraphQL tooling — so diffs stay small.

Queries and SDL

Operations, fragments, inline fragments, directives and variables, plus type system definitions with descriptions, default argument values, list and non-null types, unions and interface lists.

Safe minification

Only insignificant characters are removed: commas, whitespace and comments. Strings, block strings and numbers are kept byte-for-byte, and formatting the minified output gives back the formatted original.

Precise errors

Every unmatched (, [ or {, mismatched closer, unterminated string and illegal character is reported with its line and column.

Request builder

JSON body with query, operationName and variables (placeholders typed from the variable definitions), plus cURL and fetch versions.

Formatting rules in brief

InputFormatted output
{user{id name}}each field on its own line, indented under user {
f(a:1 b:2)f(a: 1, b: 2) — commas are optional in GraphQL; the formatter adds them for readability
...F / ...on T...F / ... on T
$id:ID!=1$id: ID! = 1
two operations in one documentseparated by one blank line
# commentkept on its own line (or removed when “Keep comments” is off)

What the checker does — and does not — validate

The formatter checks GraphQL syntax structure: that brackets balance, strings close and only legal characters appear. It does not check your document against a schema, so a misspelt field name or a missing required argument will format without complaint — your server or a schema-aware tool such as GraphiQL reports those.

Commas really are optional in GraphQL: the specification treats them like whitespace. That is why the minifier can drop them, and why the formatter inserts them consistently between arguments, list items and object fields.

Sending GraphQL over HTTP

Almost every GraphQL server accepts a POST with Content-Type: application/json and a body of {"query": "…", "operationName": "…", "variables": {…}}, as described by the GraphQL over HTTP specification. operationName is required when the document contains more than one operation. To run the request and inspect the response from this site, paste the cURL into the cURL to Fetch converter or build it in the HTTP Request Builder; pretty-print the JSON response with the JSON Formatter.

GraphQL Formatter FAQ

How do I format a GraphQL query online?

Paste it into the GraphQL formatter and press Format. The result is indented, one field per line, with arguments separated by commas; copy it or download a .graphql file.

Does it format GraphQL schemas (SDL) too?

Yes. Type, interface, enum, union, input, scalar, schema, directive and extend definitions are supported, including descriptions in quotes or triple quotes and default argument values.

Is minified GraphQL still valid?

Yes. The minifier only removes characters the GraphQL specification ignores — whitespace, commas and comments — and keeps a space where two names or numbers would otherwise merge.

Why does the formatter report an error I cannot see?

Look at the line and column given. Common causes are a closing ] where ) was needed, a quote that is never closed, or a character such as a semicolon or single quote, which GraphQL does not allow outside strings.

Will it validate my query against my API?

No — it checks syntax only. Field names, argument types and fragments are validated by your GraphQL server or a schema-aware editor.

Are comments preserved?

When “Keep comments” is ticked, each # comment is kept on its own line at the current indentation. Minify always removes comments.

You might also need