{{ summaryHeadline }}
{{ summaryDetail }}
{{ profileLabel }} {{ roleLabel }} {{ definitionCountLabel }} {{ warningCountLabel }}
GraphQL formatter input
Pick a profile first, then tune visible options when the document needs a team-specific handoff.
Paste one GraphQL document or drop a .graphql, .gql, or .txt file onto the editor.
{{ fileStatus }}
Use Auto detect for normal paste work; choose a role when reviewing operation-only or schema-only files.
{{ indentLabel }}
Use 2 or 4 spaces for most GraphQL repositories.
spaces
Turn off when the formatted handoff should behave like a production persisted-query body.
{{ preserve_comments ? 'On' : 'Off' }}
Leave on for repository files; turn off for exact clipboard payloads.
{{ final_newline ? 'On' : 'Off' }}

          

          
Artifact Bytes Lines Delta vs input Review note Copy
{{ row.artifact }} {{ row.bytesLabel }} {{ row.linesLabel }} {{ row.deltaLabel }} {{ row.note }}
Definition Name Kind Signals Copy
{{ row.definition }} {{ row.name }} {{ row.kind }} {{ row.signals }}
Check Status Detail Copy
{{ row.check }} {{ row.status }} {{ row.detail }}

        
Customize
Advanced
:

GraphQL source often moves through several hands before it reaches a service: a pull request, an API console, a client file, an operation registry, or a schema review. A document can be easy for a machine to tokenize and still be hard for a person to review when nested fields, variables, directives, and fragments have been squeezed into one line.

Readable formatting gives that source a shape again. Indentation makes parent and child selections visible, line breaks show where definitions begin and end, and comments can stay beside the query or schema part they explain. Compact formatting has a different job. It removes spacing that GraphQL ignores so a named operation can be stored, compared, or sent as a smaller payload after it has already been checked in the right environment.

Common GraphQL document types and formatting concerns
Text type What it usually contains Formatting concern
Operation document Queries, mutations, subscriptions, variables, directives, and selection sets. Nested fields and operation names must stay clear enough for review and handoff.
Fragment set Reusable selections that are spread into one or more operations. Fragment names and type conditions need to remain easy to spot.
Schema SDL Types, fields, arguments, enums, inputs, unions, directives, and schema roots. Definition boundaries matter because a small misplaced brace can hide a schema mistake.
Persisted query body A compact executable operation, often named and stored apart from variables. Comments and optional whitespace can disappear, but operation identity still matters.
GraphQL document anatomy showing executable text, fragments, schema SDL, and a schema validation boundary.

GraphQL gives whitespace, line breaks, comments, and commas very little semantic weight. A formatter can change many of those characters while keeping the same names, strings, numbers, variables, directives, and punctuators in order. That does not make formatting a substitute for validation. A tidy query can still request a field that the target schema does not have, use a fragment on the wrong type, pass the wrong variable shape, or depend on a directive the service does not support.

Separate readability from correctness. Formatting helps people review the text, compare payload size, and notice structural mistakes such as unclosed strings or brackets. The final verdict for an operation still comes from the GraphQL service, client compiler, or schema-aware validator that knows the actual type system.

How to Use This Tool:

Start with the intended handoff, then check the warning state before copying the readable or compact result.

  1. Choose Formatting profile. Use Review workspace for readable inspection, Persisted query handoff when you need compact executable text, Schema SDL cleanup for type definitions, or Custom after changing the visible settings yourself.
  2. Paste the GraphQL text into GraphQL document, drop a supported file onto the editor, use Browse GraphQL, or load Sample. The file picker accepts .graphql, .gql, and .txt files under 1 MB.
  3. Set Document role when the source has a known purpose. Auto detect works for normal pasted snippets, while the operation, schema, and mixed roles add warnings when the detected definitions do not match the intended use.
  4. Pick Indent width from 1 to 8 spaces. Two spaces is a common GraphQL default; four spaces may match repositories that use wider indentation.
  5. Open Advanced when comments or the trailing newline matter. Keep comments applies to the readable Formatted Document; Persisted Query removes comments regardless of that switch. Final newline is useful for saved files and can be turned off for exact clipboard text.
  6. Read the summary and warning alert. Syntax Needs Review, an unclosed string message, an unexpected character, or an unmatched bracket means the compact payload should wait until the source is fixed.
  7. Use Formatted Document for readable review, Persisted Query for compact text, Payload Footprint for byte and line comparison, Definition Inventory for detected definitions, Formatter Audit for status checks, and JSON when you need a structured report of the current run.

Interpreting Results:

Trust the warning state before trusting the output. GraphQL Formatted Locally, Persisted Query Ready, or Schema SDL Formatted means the browser pass could read the text, balance brackets, and produce the selected artifacts. Formatted with Caveats means output exists, but role mismatch, operation naming, or size warnings need review.

Formatter Audit is the strongest final local check. Bracket structure should be Balanced before a compact body is copied. Role fit should match the handoff. Operation naming matters when more than one executable operation appears or when persisted-query systems, tracing, caching, or registries expect stable names.

GraphQL formatter result signals and next checks
Signal Meaning Next check
Syntax Needs Review A token, string, block string, or bracket structure could not be read safely. Fix the first warning, then recheck Bracket structure.
Definition Inventory Top-level operations, fragments, schema definitions, extensions, and directives were detected from the source text. Confirm the names and kinds match the file you meant to prepare.
Payload Footprint The original, readable, and compact artifacts are compared by UTF-8 bytes and line counts. Use the compact byte count only after syntax warnings are gone.
Schema-aware validation The local pass does not know your service schema. Validate important operations with the target GraphQL service, schema checker, or client build.

Technical Details:

A GraphQL document is read as source text made of lexical tokens and ignored characters. Names, numbers, strings, block strings, punctuators, and spread markers carry the structure. Spaces, line terminators, comments, and commas mainly separate tokens and improve readability. A formatter can move line breaks and indentation when the significant token order stays the same.

The hard boundary is the schema. Syntax answers whether the document can be read as GraphQL-shaped text. Validation answers whether the document is meaningful for a particular type system, including field existence, argument names, fragment type conditions, variable usage, directive locations, and required input values. A local formatting pass can catch structure problems, but it cannot prove server acceptance without the schema.

Transformation Core:

GraphQL formatting transformation stages
Stage Rule Why it matters
Normalize line endings Source text is treated with a consistent line model. Line counts, longest-line checks, and warning locations stay comparable after paste or file loading.
Read lexical tokens Names, numeric values, quoted strings, block strings, comments, spread markers, and GraphQL punctuators are identified. Unclosed strings and unknown characters become warnings before compact output is trusted.
Check paired punctuation Braces, parentheses, and square brackets are matched with a stack-style balance check. Balanced punctuation is required for safe formatting, but it does not validate fields or types.
Write readable text Nested selection sets and schema blocks are indented with the selected width, while comments are kept or stripped according to the readable-output setting. Reviewers can see parent fields, child fields, arguments, fragments, and schema definitions more clearly.
Write compact text Comments, optional commas, and unnecessary whitespace are removed while required separators between adjacent tokens remain. Persisted-query handoff gets a smaller body without changing the readable token order.
Summarize definitions Operation starts, anonymous selection sets, fragments, SDL definitions, extensions, and directive definitions are grouped into inventory rows. The inventory can reveal a schema snippet in an operation file, or an operation accidentally mixed into SDL.

Rule Core:

GraphQL formatter rule checks
Check Local rule Reported signal
Executable starts query, mutation, subscription, anonymous selection sets, and fragment starts are counted as executable definitions. Definition Inventory reports operations and fragments with variables, directives, selection blocks, and comment counts.
Schema starts schema, type, input, enum, interface, union, scalar, directive, and supported extend forms are counted as SDL definitions. Role fit warns when schema definitions appear in an operation-only handoff, or operations appear in a schema-only file.
Mixed role A mixed document is expected to contain at least one executable definition and at least one schema definition. A warning appears when one of those definition families is missing.
Persisted-query handoff Compact handoff expects at least one executable query, mutation, or subscription. Multiple executable operations or anonymous operations deserve review. Operation naming warns when a stable operation name may be needed.
Large source Source text above 1 MB receives a browser-performance warning. Formatting can still be attempted, but mobile review may be slower.
Schema-aware validation No schema is loaded during the local pass. Formatter Audit reports Not run for field, type, fragment, directive, and variable validation.

Mechanism Walkthrough:

A compact operation such as query GetOrder($id:ID!){order(id:$id){id status}} is tokenized into the operation keyword, operation name, variable marker, names, punctuation, and selection-set braces. The readable output adds line breaks after structural braces and indents id and status under order. The compact output keeps the same semantic tokens and removes spacing that is not needed between them.

The same pass handles comments differently by output purpose. A review copy can keep # comments so teammates see context beside the query or SDL. A persisted-query body strips comments because GraphQL comments are ignored during execution and should not be part of a compact handoff payload.

Formula Core:

Payload comparison uses UTF-8 byte counts rather than visible character counts, so non-ASCII text inside strings or comments is measured by transport size.

Delta vs input

Delta percent = Output bytes - Input bytes Input bytes × 100

For example, a 1,200-byte source that becomes an 840-byte compact payload has a delta of -30.0%. A formatted review copy can show a positive delta when indentation and final newline settings add bytes.

The formatter is deterministic for the current text and settings. It is best understood as a local formatting, footprint, and structural-review pass, not a complete GraphQL parser, query planner, or schema validator.

Privacy Notes:

Pasted GraphQL text and selected files are processed in the browser for formatting, inventory, payload comparison, audit rows, and JSON output. Avoid including secrets, bearer tokens, customer identifiers, or production-only examples in text that you plan to copy, download, or share.

Worked Examples:

Review a query before an API-console test

A paste containing query GetOrder($id: ID!) with a nested order selection works well with Review workspace and Auto detect. Formatted Document should show the nested fields on separate indented lines, and Definition Inventory should include the named operation with variable and selection-block signals.

Prepare a persisted-query body

A named operation that has already passed schema validation can use Persisted query handoff. Persisted Query should become a one-line body with comments and optional commas removed. Before copying it, check Formatter Audit for Bracket structure set to Balanced and Operation naming set to Ready.

Clean up schema SDL for a pull request

A schema snippet such as type Query { order(id: ID!): Order } should use Schema SDL cleanup or Document role set to Schema SDL document. Definition Inventory should report schema definition rows, while Role fit warns if an executable query or fragment is accidentally mixed into the SDL file.

Fix an unclosed string before handoff

If a string starts with " and never closes, the warning alert should name the unclosed string location, the summary should show Syntax Needs Review, and Persisted Query should remain unavailable. Close the string first, then return to Formatter Audit before using the compact output.

FAQ:

Does formatted GraphQL mean my query will run?

No. Formatting and bracket checks do not confirm field names, argument types, directive support, fragment validity, or server-specific schema rules.

Why does the compact output remove comments?

GraphQL comments are ignored during execution. Persisted Query always strips them so the compact body contains only the executable token text.

Why did a role warning appear?

The selected Document role did not match the detected definitions. For example, operation-only mode warns when SDL definitions such as type or directive appear.

What file types can I load?

You can load GraphQL, GQL, or plain text files. Files over 1 MB are rejected so in-browser formatting remains manageable.

Why is the persisted-query result unavailable?

A tokenization or bracket problem blocked the compact body. Fix the warning first, then check that Bracket structure is Balanced.

Does my GraphQL text leave the browser?

The formatting pass, selected-file reading, inventory, footprint comparison, audit rows, and JSON report are generated locally in the browser.

Glossary:

Operation
A GraphQL query, mutation, or subscription that can be executed by a GraphQL service.
Selection set
The fields inside braces that describe the data requested from a parent field or operation.
Fragment
A reusable selection set that can be included in operations or other fragments.
Directive
An annotation beginning with @ that can affect execution, validation, schema behavior, or tooling depending on where it appears.
Schema SDL
GraphQL schema definition language, the text form used to describe types, fields, arguments, directives, and root operation types.
Persisted query
A compact executable operation commonly stored or identified separately from the variables sent with a request.
Schema-aware validation
A check that compares an operation with the target GraphQL type system, including fields, variables, fragments, and directives.

References: