GraphQL Formatter
Format and beautify GraphQL code as you type, right in your browser, then copy or download it, or switch to any other language.
Input
Output
Readme
What does a code formatter do?
A code formatter rewrites code in a consistent style without changing what it does. It puts every statement, rule, and tag on its own line, indents nested blocks, spaces out operators, and lines up lists, so code that was minified, pasted from a chat, or written in a hurry becomes easy to read and compare. Teams use formatters so that everyone's code looks the same and reviews show real changes instead of whitespace.
Tool description
Paste or type your code and the formatted version appears as you type. Pick the language, then choose whether nested lines are indented with 2 spaces, 4 spaces, or tabs. Copy the result or download it as a file with the right extension.
Each tool starts on the language in its name, and you can switch to any other language from the menu. HTML, CSS, SCSS, Less, JavaScript, TypeScript, Vue, GraphQL, YAML, and Markdown are formatted by Prettier, the formatter most web projects use. HTML and Vue files have their <style> and <script> blocks formatted too, JavaScript can contain JSX, and Vue scripts can be TypeScript.
SQL is formatted by sql-formatter, which knows the keywords, operators, and quoting rules of each dialect, such as square-bracketed names in T-SQL, :: casts in PostgreSQL, and backticks in MySQL and MariaDB. Choose the dialect your database uses for the best results, and pick whether keywords like SELECT and FROM are written in upper case, lower case, or as you typed them.
When the code can't be read, for example because of a missing bracket or an unclosed string, the tool shows the parser's message with the line and column where it stopped. JSON has its own tool, the JSON Formatter.
Languages
| Language | Formatted by | Notes |
|---|---|---|
| HTML | Prettier | Includes inline CSS and JavaScript |
| CSS | Prettier | |
| SCSS | Prettier | Sass with curly braces |
| Less | Prettier | |
| JavaScript | Prettier | Modern syntax and JSX |
| TypeScript | Prettier | Includes TSX |
| Vue | Prettier | Single-file components |
| GraphQL | Prettier | Queries, mutations, and schemas |
| YAML | Prettier | YAML can't contain tabs, so tabs become spaces |
| Markdown | Prettier | Headings, lists, tables, and emphasis |
| SQL | sql-formatter | Standard SQL |
| MySQL | sql-formatter | |
| MariaDB | sql-formatter | |
| PostgreSQL | sql-formatter | |
| SQLite | sql-formatter | |
| T-SQL | sql-formatter | Microsoft SQL Server |
| PL/SQL | sql-formatter | Oracle |
| BigQuery | sql-formatter | Google BigQuery |
| Snowflake | sql-formatter | |
| Redshift | sql-formatter | Amazon Redshift |
| Spark SQL | sql-formatter | Apache Spark and Databricks |
Features
- Formats as you type, with syntax highlighting on both sides
- Web languages, YAML, Markdown, and the SQL dialects of popular databases
- Indentation with 2 spaces, 4 spaces, or tabs
- Upper case, lower case, or unchanged SQL keywords
- Shows where the code stops being valid
- Copy or download the result
- Runs in your browser, so your code never leaves your device