Code formatting guides

Review a GraphQL catalog query after formatting

·

When a GraphQL operation arrives on one line, indent its selection sets so you can see where a fragment and its directive apply.

GraphQL Formatter

Find the directive on the fragment spread

Select Load query example and keep two spaces. Format GraphQL. The Catalog operation contains inventory. Both label and the spread named Stock sit inside that selection set.

The default for $show is true and the @include directive stays on the Stock spread. The comment Catalog screen stays above the operation. The result reports two definitions checked.

GraphQL September 2025 — Language

Check a block description and an input default

Load schema example, set Indentation to four spaces and format. The description Stock from the morning count. remains attached to Item. The StockFilter input keeps its minimum default of 0.

Download GraphQL and open the file in your editor. Check the two definitions and verify that nested fields show the four-space indent.

Prettier — Browser standalone API

Use the parser location to fix an incomplete argument

Enter query Catalog { on line 1, list( on line 2 and } on line 3. Format GraphQL. The parser reports line 3, column 1 because the closing brace appears where an argument name was expected. Add the intended argument and its closing parenthesis before formatting again.

Common questions

Do commas determine the meaning of a GraphQL variable list?

GraphQL treats commas as insignificant in its grammar. The parser compares the actual variable definitions and argument values.

Can the formatter check whether my server exposes these fields?

Field availability is checked by validating the operation against the destination schema. This tool works on the supplied document syntax.

Sources

Put it into practice.

Related guides