Last updated
Formatting Rules Applied
- 2-space indentation for each nesting level
- Each field on its own line
- Opening brace on the same line as the type/operation
- Closing brace on its own line
- Blank line between top-level definitions (types, fragments, operations)
- Arguments on the same line when they fit; one per line when they don't
- Directives on the same line as the field they apply to
- Fragment spreads indented within their parent selection set
- Syntax validation before formatting — errors reported with line/column numbers
Examples
Example 1: Formatting a Query
Before (minified / unformatted):
query GetUser($id: ID!) { user(id: $id) { id name email profile { avatar bio location } posts(first: 10) { edges { node { id title createdAt } } } } }
After formatting:
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
profile {
avatar
bio
location
}
posts(first: 10) {
edges {
node {
id
title
createdAt
}
}
}
}
}
Example 2: Formatting a Mutation
Before:
mutation CreatePost($input: CreatePostInput!) { createPost(input: $input) { id title content author { id name } tags { id name } createdAt } }
After formatting:
mutation CreatePost($input: CreatePostInput!) {
createPost(input: $input) {
id
title
content
author {
id
name
}
tags {
id
name
}
createdAt
}
}
Example 3: Formatting with Fragments
Before:
fragment UserFields on User { id name email avatar } query GetUsers { users { ...UserFields posts { id title } } }
After formatting:
fragment UserFields on User {
id
name
email
avatar
}
query GetUsers {
users {
...UserFields
posts {
id
title
}
}
}