Skip to content

GraphQL Formatter

Format and beautify GraphQL queries, mutations, and schemas online. Free GraphQL formatter with syntax validation and configurable indentation.

0 characters

About GraphQL Formatter

Format and beautify GraphQL queries, mutations, subscriptions, fragments, and schema definitions with proper indentation. Supports directives (@deprecated, @skip, @include), arguments, variables, inline fragments, union types, interfaces, enums, and more. Validates bracket/brace/parenthesis matching and reports syntax errors.

How to Use GraphQL Formatter

1

Paste GraphQL query/SDL

Drop in any GraphQL document — a query, mutation, subscription, or schema definition. The formatter detects the operation type automatically by parsing the document, so you don't need to specify whether you're working with executable operations or schema language. The same input handles minified queries copied from a network panel and unformatted schemas pulled out of a repository.

2

Configure formatting (optional)

The defaults match what most teams use — 2-space indentation, fields on separate lines, no trailing commas — but you can adjust them. Some teams prefer 4-space indentation for closer alignment with their other code, or specific bracket placement to match a house style. The configuration sticks across documents within a session, so you only set it once.

3

View formatted output

The result lays the document out with proper indentation and line breaks, exposing the field hierarchy at a glance. Five-level nesting that looked like a wall of braces in the input becomes obviously structured. Worth noting that depth visibility makes performance problems easier to spot — N+1 patterns at the resolver layer often hide behind compact queries that look harmless until you format them.

4

Copy formatted result

Copy the formatted document straight to your clipboard. The formatted form is what you want for documentation, code reviews, and committed files where readability matters. For the actual network requests during runtime, most production setups use the minified form to reduce payload size — the format-during-development, minify-before-transport pattern that's standard across GraphQL tooling.

When to Use GraphQL Formatter

API debugging

GraphQL queries become unreadable surprisingly fast — three nested levels in and the whole thing is a wall of curly braces and angle brackets. Pretty-printing with proper indentation makes the field hierarchy obvious, which is half the battle when you're trying to figure out why a particular field isn't returning. API consumers, backend developers fielding integration questions, and QA engineers who get raw queries pasted into tickets all benefit from formatting before reading.

Documentation and examples

GraphQL examples in API docs, blog posts, and tutorials need to be readable, and minified queries pasted from a network panel definitely aren't. Running them through a formatter before publishing produces consistent style across all your examples and saves readers from squinting at one-line monsters. Worth running every snippet through the same formatter so the whole doc reads in one voice.

Schema review

Schema review meetings — looking at proposed types and fields, debating naming, checking for unused entries — go better when the SDL is formatted cleanly. Type definitions on their own lines, consistent spacing around colons, and proper indentation for nested types make it much easier to spot omissions or inconsistencies. Useful for API governance reviews and onboarding new team members to a large schema.

Query optimization

Formatted queries reveal performance problems that minified ones hide. Five levels of nesting that produce N+1 query patterns at the resolver layer become visible once the indentation calls them out. Same goes for opportunities to consolidate repeated field selections into a fragment — easier to spot the duplication when each query reads cleanly.

GraphQL Formatter Examples

Query formatting

Input
query{user(id:1){name email posts{title}}}
Output
query {\n  user(id: 1) {\n    name\n    email\n    posts {\n      title\n    }\n  }\n}

The same query laid out with proper indentation and spacing around the argument colon. Each level of nesting steps in two spaces, and each field gets its own line. The structure is now obvious at a glance — you're querying a user, pulling three fields, one of which is a relationship to posts.

Mutation with variables

Input
mutation($id:ID!){updateUser(id:$id){name}}
Output
mutation($id: ID!) {\n  updateUser(id: $id) {\n    name\n  }\n}

Mutations format the same way as queries. The variable declaration in the parentheses keeps its type annotation (ID! means non-null ID), and the call site references the variable with a dollar sign. Useful in client code where you want to hand the formatted version to someone implementing the mutation.

Schema SDL

Input
type User{id:ID! name:String posts:[Post!]}
Output
type User {\n  id: ID!\n  name: String\n  posts: [Post!]\n}

Schema Definition Language reformatted with each field on its own line. The non-null markers (!) and list syntax ([Post!]) come through unchanged. This is the form you'd commit to a schema.graphql file, where reviewing diffs depends on each field being on its own line.

Tips & Best Practices for GraphQL Formatter

  • 1.Use fragments to deduplicate field selections. Defining 'fragment UserBasic on User { name email }' once and then referencing it as ...UserBasic in three queries makes them all shorter and ensures they stay in sync when you add a field.
  • 2.Aliases let you query the same field multiple times in one round trip. 'user1: user(id: 1) { ... } user2: user(id: 2) { ... }' returns both users under different keys — useful for batch operations and avoiding cache key collisions.
  • 3.Reach for variables instead of hardcoded values. Sending '$id' as a separate variable rather than embedding the literal id keeps queries cacheable, lets the same query handle different inputs, and avoids injection-style problems with user-supplied data.
  • 4.Format before committing. Consistent formatting across the team makes diffs cleaner and code reviews faster. A pre-commit hook running the formatter saves the manual step and keeps style drift out of the codebase.
  • 5.Use a real GraphQL client during development. Apollo Sandbox, GraphiQL, Insomnia, and Postman all auto-format and add schema-aware autocompletion, which beats round-tripping through a standalone formatter for active development work.
  • 6.Watch the depth. Five-level-deep queries can produce N+1 patterns at the resolver layer that look fine in isolation but melt the database under load. Formatted output makes depth obvious, which makes it easier to spot when a query is asking for too much.

Frequently Asked Questions

It's a query language for APIs that emerged from Facebook in 2015 as a structural alternative to REST. Instead of an endpoint per resource, GraphQL exposes a single POST endpoint and lets the client describe exactly which fields it wants in the response. The schema declares the types and the available operations up front, which gives clients a strongly typed contract to work against. The model has been adopted broadly since — GitHub, Shopify, Apollo, and a long list of internal company APIs all run on GraphQL alongside or instead of REST.