Format GraphQL

Format a GraphQL document with readable selection sets, arguments, and fragments.

freeworks offlinenothing uploaded
ToolGraphQL Formatter
Input
Output
—

How it works

GraphQL punctuation, names, arguments, selections, and fragments are tokenized and emitted with consistent indentation and line breaks. Comments and string values stay attached to their syntax.

  • Two-space indentation suits nested-query review.
  • Compact mode keeps a document suitable for transport.

Worked example

Format a GraphQL query
Add proper indentation to a compressed GraphQL query
Input
											query { user(id: 1) { name email posts { title } } }
										
Output
												query  {
  user(id: 1)  {
    name email posts  {
      title
    }
  }
}
											

When to use this

Apollo queries, introspection debugging, and persisted-query normalization format GraphQL.

Edge cases

  • Braces inside a string are values, not selections.
  • Block strings preserve intentional newlines.
  • Aliases and fragment spreads have distinct token roles.

References