GraphQL Formatter & Beautifier

Format, beautify, and clean up your GraphQL queries and schemas instantly.

Input GraphQL
Output
Formatted output will appear here...
info

About GraphQL Formatter

GraphQL Formatter is a free online tool that takes minified, compressed, or poorly indented GraphQL operations and restructures them into cleanly formatted code with consistent indentation and proper nesting. Paste a single-line query string pulled from a network inspector, a multi-operation document with fragments and variables, or a full schema definition — the formatter returns readable output instantly.

GraphQL queries accumulate complexity quickly. A small selection set grows into deeply nested field groups with inline arguments, directives, and aliases. When that query ends up on one line in a log file, a curl request, or a client-side constant, it becomes nearly impossible to reason about. The formatter separates every field onto its own line and indents each nesting level, so the structure of the selection is visible at a glance. A separate Minify button strips whitespace and comments in the opposite direction, producing a compact single-line query ready for embedding in source code or sending over the wire.

All formatting runs entirely in your browser using a custom parser built in JavaScript. Nothing you paste — including internal API queries, private schema definitions, or auth tokens in variables — is uploaded, logged, or transmitted to any server. The tool is free, requires no sign-in, and works offline once the page has loaded.

star

Key Features

check_circle

Indents all operation types

Handles queries, mutations, subscriptions, and schema type definitions with identical formatting rules — each closing brace is dedented automatically.

check_circle

Configurable indentation

Switch between 2 spaces, 4 spaces, or hard tabs using the toolbar toggle before you click Format, so the output matches your project style guide.

check_circle

Minify in one click

The Minify button collapses the query to a single line and strips comments, producing the compact form needed for API calls, curl commands, and inline string constants.

check_circle

Argument-aware field splitting

Fields that carry parenthesized arguments — such as posts(first: 10, orderBy: DESC) — are kept on one line rather than split at the space, so arguments stay attached to their field.

check_circle

Download as .graphql file

Save the formatted output directly as a .graphql file for checking into version control or sharing with teammates, without leaving the browser.

check_circle

100% client-side privacy

The entire format and minify pipeline runs in your browser tab. Confidential queries, internal schema files, and auth headers in variable objects never leave your machine.

help

How to Use

01

Paste Your Query

Copy your GraphQL query, mutation, or schema and paste it into the input editor on the left.

02

Format or Minify

Click "Format" to beautify with proper indentation, or "Minify" to compress for network efficiency.

03

Copy the Result

Use the copy button to grab your formatted GraphQL, or download it as a .graphql file.

code_blocks

Example

A single-line query with nested fields and arguments is expanded into an indented, human-readable document with each field on its own line.

Minified GraphQL input
query GetPost($id: ID!) { post(id: $id) { id title author { name avatar { url } } comments(first: 5) { edges { node { id body } } } } }
Formatted output (2 spaces)
query GetPost($id: ID!) {
  post(id: $id) {
    id
    title
    author {
      name
      avatar {
        url
      }
    }
    comments(first: 5) {
      edges {
        node {
          id
          body
        }
      }
    }
  }
}
lightbulb

Common Use Cases

  • arrow_circle_right

    Decoding queries from network logs

    When you copy a GraphQL request body from browser DevTools or a server log, it arrives as a single compressed line. Formatting it makes the field selection and arguments readable so you can debug the request without eyestrain.

  • arrow_circle_right

    Code review of API changes

    Reviewing a pull request that changes a long query string is near-impossible when the operation is minified. Format both versions to see exactly which fields were added, removed, or reordered.

  • arrow_circle_right

    Cleaning up generated client queries

    Code generators such as graphql-codegen sometimes produce long operation strings in TypeScript files. Paste the raw string here to understand its structure before modifying it by hand.

  • arrow_circle_right

    Preparing queries for documentation

    API documentation and README examples need properly indented code samples. Use the formatter to produce a clean, indented version ready to paste into Markdown or Notion.

  • arrow_circle_right

    Compressing queries for production builds

    The Minify button removes all whitespace and comments from a formatted query, reducing the payload size of GraphQL requests in production apps and making it safe to inline into TypeScript string literals.

quiz

Frequently Asked Questions

What is a GraphQL Formatter? expand_more
A GraphQL Formatter is a tool that takes GraphQL queries, mutations, subscriptions, or schema definitions and restructures them with consistent indentation and line breaks, making nested field selections easy to read.
Does this tool support mutations and subscriptions? expand_more
Yes. The formatter handles all GraphQL operation types including queries, mutations, subscriptions, and schema type definitions with proper indentation for nested fields.
Is my GraphQL query secure? expand_more
Yes. All formatting is performed locally in your browser. Your queries never leave your machine and are not sent to any external server.
Can I customize the indentation? expand_more
Yes. Choose between 2 spaces, 4 spaces, or tab-based indentation using the selector in the toolbar before formatting.
How is this different from a JSON Formatter? expand_more
A JSON Formatter parses and indents JSON data structures — objects, arrays, and scalar values. This GraphQL Formatter understands GraphQL operation syntax specifically: it correctly handles selection sets, inline arguments with parentheses, operation names, variable definitions, and directives that have no equivalent in JSON. If your data is already JSON (for example, the response body of a GraphQL API call), use the JSON Formatter instead.
How is this different from a SQL or JS Formatter? expand_more
SQL and JS formatters parse entirely different languages with their own grammar rules. This tool is designed exclusively for GraphQL operation documents and schema files. It keeps arguments inline with their field, handles the { } nesting pattern that GraphQL uses for selection sets, and produces output that matches .graphql file conventions.
Can I format a full schema definition file? expand_more
Yes. Paste a schema that includes type definitions, interfaces, unions, enums, and input types and the formatter will apply the same consistent indentation rules across all definitions.
Does minifying a query change its behavior? expand_more
No. Whitespace and comments are not semantically meaningful in GraphQL. A minified query and its formatted equivalent are parsed identically by any spec-compliant GraphQL server.
Can I upload a .graphql file instead of pasting? expand_more
Yes. Use the upload icon in the toolbar to load a .graphql, .gql, or .txt file from your computer. The contents are read locally and placed in the input pane for formatting.