What is GraphQL SDL formatting?
SDL (Schema Definition Language) is the canonical text representation of a GraphQL schema. Formatting SDL means putting each type, field, and argument on its own line with consistent 2-space indentation, descriptions immediately above their target, and directives in a deterministic order. The graphql-js print() function and Prettier with the graphql plugin both apply this convention.
Does formatting GraphQL change query semantics?
No. GraphQL is whitespace-insensitive (outside of block string descriptions). Reformatted queries, mutations, and fragments produce identical results when executed. The AST that graphql-js parses is unchanged.
How are descriptions formatted in SDL?
Descriptions use block strings (""" ... """) immediately above the type, field, or argument they describe — no blank line between. Single-line descriptions can use """short""" on one line. The June 2018 spec deprecated # comments for documentation; tooling (Apollo, GraphiQL, GraphQL Playground) only renders block-string descriptions.
In what order should directives appear?
Directives apply in the order written and most printers emit them in source order. Common conventions: @deprecated last (it is metadata about the field state); auth/access directives first (@auth, @hasRole); then transformation directives (@formatDate, @upper). Apollo Federation directives (@key, @external, @requires) are emitted in spec order.
Can it format both schema and operation documents?
Yes. SDL files (schema.graphql) with type, interface, union, enum, input, scalar, directive definitions and executable documents (queries, mutations, subscriptions, fragments) are both formatted. The output uses 2-space indentation and one field per line.
How are long argument lists wrapped?
When a field has multiple arguments, idiomatic GraphQL wraps them onto separate lines: each argument on its own line, indented one level deeper than the field. graphql-js print() and Prettier both apply this when the inline form exceeds 80 characters. Arguments with default values are kept on the same line as the argument name.
Is the GraphQL I paste sent to your servers?
No. Formatting runs entirely in your browser using JavaScript. Schemas containing internal type names, federation entity keys, or operation documents with embedded credentials never leave your device. Open DevTools → Network and click Format to verify.
Does it preserve fragments and inline fragments?
Yes. Named fragments (fragment UserFields on User { ... }), inline fragments (... on Admin { ... }), and fragment spreads (...UserFields) are formatted with the same selection-set indentation as a regular field. Type conditions stay on the same line as the spread.