GraphQL prettifier
What is a Graphql Prettifier?
GraphQL queries copied from network logs, browser developer tools or generated code often arrive as one long line. Schemas can also get messy as teams edit them. This tool formats GraphQL documents with consistent indentation and line breaks, or minifies them to a single compact line for transport.
How to use it
- Paste a query, mutation, subscription, fragment or schema definition.
- Choose prettify or minify.
- Copy the result.
Example
Input:
query GetUser($id: ID!){user(id:$id){id name posts(first:5){edges{node{title}}}}}Prettified:
query GetUser($id: ID!) {
user(id: $id) {
id
name
posts(first: 5) {
edges {
node {
title
}
}
}
}
}Why format GraphQL?
- Nested selections are much easier to review when indented.
- Consistent formatting keeps diffs small in code review.
- Formatting reveals syntax errors such as a missing closing brace.
Why minify?
Minified queries are smaller when sent as GET request parameters or stored in persisted query maps. Whitespace and commas are insignificant in GraphQL, so removing them does not change the meaning.
Tips
- Use named operations (
query GetUser) rather than anonymous ones; they appear in server logs and tracing. - Pass values through variables instead of string interpolation to avoid injection and enable caching.
- For projects, run Prettier with GraphQL support so files stay formatted automatically.
Frequently Asked Questions
Does formatting change what a GraphQL query does?
No. Whitespace and commas are insignificant in GraphQL, so formatting does not change meaning.
Can I format schema SDL files?
Yes. Type definitions, interfaces, enums and directives can be formatted as well as queries.
Why minify GraphQL queries?
Minified queries are smaller in URLs and network payloads, which helps with GET requests and persisted queries.
Why does formatting fail?
The document probably has a syntax error, such as an unbalanced brace or missing colon.
Is my query sent to a GraphQL server?
No. Formatting runs entirely in your browser and does not execute or validate the query against any API.