GraphQL Formatter

Format and beautify GraphQL code.

Local Your input is processed locally in your browser. The first run loads the open-source Prettier library from this site; your input is not sent anywhere. Found a problem? Report an issue

What the GraphQL Formatter does

The GraphQL Formatter formats GraphQL with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports GraphQL queries, mutations, fragments and schema definitions (SDL).

GraphQL Formatter examples

The built-in sample

Input

query{user(id:1){name}}

Output

query {
  user(id: 1) {
    name
  }
}

This is the input that the Load sample button fills in.

A schema type

Input

type User{id:ID!,name:String,friends(first:Int=10):[User!]!}

Output

type User {
  id: ID!
  name: String
  friends(first: Int = 10): [User!]!
}

Commas between fields are optional in GraphQL, so they are removed and each field goes on its own line. The default value and the non-null markers are kept.

Shorthand query, comment and mutation

Input

{a,b,c(x:1,y:2)}
# c
mutation{add(input:{a:1}){id}}

Output

{
  a
  b
  c(x: 1, y: 2)
}
# c
mutation {
  add(input: { a: 1 }) {
    id
  }
}

Commas between arguments are kept and spaced. The # comment stays where it was.

Each output was produced by running this tool on the input above it.

How it works

The code is parsed with Prettier's graphql parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out. If the code cannot be parsed, the parser's message with its line and column is shown instead of output.

Details and limits

  • Both operation documents (queries, mutations, subscriptions, fragments) and schema definition language are supported.
  • Only the syntax is checked. Field names and types are not validated against a schema.
  • Descriptions in triple quotes and # comments are kept.

Common errors

Message or symptomWhat it means
Syntax Error: Expected NameA missing field name, brace or parenthesis in the query.

Questions

Is my data uploaded when I use GraphQL Formatter?

No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.

What does GraphQL Formatter do?

The GraphQL Formatter formats GraphQL with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports GraphQL queries, mutations, fragments and schema definitions (SDL).

How does GraphQL Formatter work?

The code is parsed with Prettier's graphql parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out.

Are there any limits I should know about?

Both operation documents (queries, mutations, subscriptions, fragments) and schema definition language are supported. Only the syntax is checked. Field names and types are not validated against a schema.

Is there a size limit?

There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.

Does it work on phones, and is it free?

Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.