tool

GraphQL Formatter, Validator & Minifier

Format queries, mutations and schemas, find syntax errors and minify GraphQL for smaller requests.

input
0 characters
1
result

paste your code and choose format or minify

Format, validate and minify GraphQL

Paste a GraphQL query, mutation, subscription, fragment or a schema written in SDL and turn it into readable, indented code, with one field per line and nested selections clearly laid out. Validate it to catch syntax errors such as a missing brace or a misplaced argument, with the exact line and column. Or minify it into a compact single-line document for request bodies, persisted queries and URLs. Everything runs locally in your browser.

What can you do?

  1. 1. Format queries and schemas
    Operations, fragments, variables with default values, directives, input objects and type definitions (type, input, enum, interface, union, scalar, directive) are all formatted with Prettier.
  2. 2. Validate GraphQL syntax
    Get a precise message such as “Line 1, column 15: Expected Name, found "{"” when the document doesn't parse.
  3. 3. Minify GraphQL
    Remove whitespace, line breaks, # comments and optional commas. String values and """block string""" descriptions are kept exactly as written.
  4. 4. Token-verified minification
    The minified document is parsed again and compared token by token with the original, so the query your server receives is exactly the same.
  5. 5. Definition count
    See how many operations, fragments and type definitions a document contains.

Why format and minify GraphQL?

GraphQL queries are often built in one place and read in another: copied from browser network logs, pasted from an API explorer, embedded in code as single-line strings. Formatting turns those dense strings back into a structure that mirrors the shape of the response you'll get.

Minifying goes the other way. Whitespace and commas are meaningless in GraphQL, so removing them shrinks request bodies and GET URLs without changing the operation at all, which is useful for persisted queries, CDN-cached GET requests and logs.

How to format a GraphQL query

  1. 1. Paste the query or schema
    One operation, several operations with fragments, or an entire schema.graphql file.
  2. 2. Choose format, minify or validate
    The document is parsed first, so you'll know immediately if it's invalid.
  3. 3. Fix syntax errors
    Jump to the reported line and column and correct the problem.
  4. 4. Copy the result
    Paste it into your client code, API explorer or schema file.

Example: a query formatted and minified

GRAPHQLInput
query GetOrders($first:Int=10,$status:OrderStatus){orders(first:$first,status:$status){edges{node{id total customer{...CustomerFields}}}}}
fragment CustomerFields on Customer{id name email}
GRAPHQLFormatted
query GetOrders($first: Int = 10, $status: OrderStatus) {
  orders(first: $first, status: $status) {
    edges {
      node {
        id
        total
        customer {
          ...CustomerFields
        }
      }
    }
  }
}
fragment CustomerFields on Customer {
  id
  name
  email
}
GRAPHQLMinified
query GetOrders($first:Int=10$status:OrderStatus){orders(first:$first status:$status){edges{node{id total customer{...CustomerFields}}}}}fragment CustomerFields on Customer{id name email}

The minified version has no commas between variables and arguments. That's valid: commas are optional in GraphQL and are treated like whitespace, so ($a: Int, $b: Int) and ($a:Int $b:Int) mean exactly the same thing.

What a GraphQL document can contain

GraphQL definition types supported by the formatter
DefinitionUsed inExample
queryClientsquery GetUser($id: ID!) { … }
mutationClientsmutation AddItem($input: ItemInput!) { … }
subscriptionClientssubscription OnMessage { … }
fragmentClientsfragment UserFields on User { … }
type / input / enumSchemastype User { id: ID! name: String }
interface / unionSchemasunion SearchResult = User | Post
scalar / directiveSchemasdirective @auth(role: String) on FIELD_DEFINITION
extendSchemasextend type Query { me: User }

Frequently asked questions

Does validation check my query against a schema?

No. It checks GraphQL syntax only. Whether a field exists, an argument has the right type or a fragment matches its type depends on your server's schema, which tools like GraphiQL, Apollo Studio or graphql-codegen check against.

Are comments kept?

Formatting keeps # comments. Minifying removes them, because they are ignored by GraphQL servers. Descriptions written as strings ("…" or """…""") are part of the schema, so they're always kept.

Can I minify a schema (SDL) as well as queries?

Yes. Type definitions, directives and descriptions minify the same way as operations.

Will a minified query still work with my GraphQL client?

Yes. Apollo, Relay, urql and plain fetch requests send the query as a string, and any spec-compliant server parses the minified version exactly like the formatted one.

Is my query or schema uploaded?

No. Everything is processed in your browser.

Turning a GraphQL response into types? Paste the JSON into the JSON to TypeScript converter.