# GraphQL formatter

Format, minify, and validate GraphQL queries, mutations, fragments, and SDL schemas in your browser.

## Run it

- **CLI:** `gizza tool graphql-formatter 'query Hero($episode: Episode = JEDI) { hero(episode: $episode) { name friends { name } } }'`
- **Web:** https://gizza.ai/tools/graphql-formatter/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/graphql-formatter/tool.json

## Inputs

- `input` — GraphQL input _(field)_
- `indent` — Indent _(field)_
- `mode` — Mode _(field)_
- `sort_fields` — Sort fields _(field)_
- `remove_comments` — Remove comments _(field)_

## Output

- Result (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `input` — GraphQL input
- `indent` — Indent
- `mode` — Mode
- `sort_fields` — Sort fields
- `remove_comments` — Remove comments

Example: `https://gizza.ai/tools/graphql-formatter/?input=query%20Hero%28%24episode%3A%20Episode%20%3D%20JEDI%29%20%7B%20hero%28episode%3A%20%24episode%29%20%7B%20name%20friends%20%7B%20name%20%7D%20%7D%20%7D&indent=2&mode=format&sort_fields=true&remove_comments=true`

---

## About this tool

Paste a GraphQL query, mutation, subscription, fragment, or SDL schema and get a validated, consistently formatted document back. The formatter parses the GraphQL grammar before printing, so syntax errors include a line and column instead of silently rearranging invalid text.

Use the indent selector for two spaces, four spaces, eight spaces, or tabs. Choose **minify** when you need a compact payload for examples or tests, enable **sort fields** for stable diffs, and enable **remove comments** when you want formatted output without `#` notes.

Worked example:

Input:

```graphql
query Hero($episode: Episode = JEDI) { hero(episode: $episode) { name friends { name } } }
```

Output with the default settings:

```graphql
query Hero($episode: Episode = JEDI) {
  hero(episode: $episode) {
    name
    friends {
      name
    }
  }
}
```

Limits and edge cases: input is capped at about 500 KB, nesting is capped at 64 levels, minify mode always removes comments, and the parser focuses on standard GraphQL executable documents and SDL definitions rather than vendor-specific non-GraphQL template wrappers.

## FAQ

<details>
<summary>Does this validate the GraphQL syntax?</summary>

Yes. The tool lexes and parses the document before printing it. If the source is not valid GraphQL, the output shows a syntax error with a line and column so you can jump to the problem.

</details>

<details>
<summary>Can it format schema definition language as well as queries?</summary>

Yes. It handles operations, fragments, schema definitions, object and input types, enums, unions, scalars, directives, descriptions, and common SDL extensions.

</details>

<details>
<summary>What does sort fields change?</summary>

It sorts selection fields recursively and sorts object/input fields in SDL blocks. That is useful for stable generated diffs, but leave it off when field order is meaningful for human review.

</details>

<details>
<summary>Does minify preserve comments?</summary>

No. GraphQL comments are ignored tokens, so minify mode drops them. If you want readable output with comments removed, use format mode with **Remove comments** enabled.

</details>

## Related tools

- [Align Text into Neat Columns](https://gizza.ai/tools/column-aligner/): Paste whitespace-, tab-, comma-, or pipe-delimited text and align it into neat fixed-width plain-text columns with Unicode-aware padding.
- [CSV Cell Diff](https://gizza.ai/tools/csv-cell-diff/): Compare two CSVs column-by-column and highlight every individual cell that changed, plus added and removed rows and columns.
- [Compare Two Code Snippets](https://gizza.ai/tools/diff-code/): Paste two code snippets and compare them side by side, with word- or character-level highlighting, a unified patch view, and change stats.
- [Extract both file versions from a diff](https://gizza.ai/tools/diff-extract-versions/): Paste a unified diff and get both file versions back. Reconstructs the original and patched text from a git diff or .patch alone, no source file needed.
- [DynamoDB JSON Converter](https://gizza.ai/tools/dynamodb-json-converter/): Convert between DynamoDB typed AttributeValue JSON and plain JSON in both directions, with auto-detect and pretty or compact output.
