Pikkola Schema Lab, tool No. 54

One document, four ways to read it.

Paste a query or a schema. Get it formatted to two or four spaces, compressed to a single line, turned into TypeScript types, and answered with a mock response shaped by the selection set. The same document, read four ways, in this tab.

4
readers
2/4
space indent
0
requests sent

The studio

One document, two boxes

The left box holds the document: a query, a mutation, a fragment or a whole schema. The right box answers. Every press reads the document again, so what you see is what the parser understood.

Presets
The document query
Schema optional

TypeScript and mock data read this box. Formatting and checking work without it.

The answer document.graphql

              
            
0lines
0fields
0depth
0cost
0variables
0fragments

Four starts

Documents worth reading twice

Each card loads a document and the schema it belongs to, so the TypeScript and the mock answer straight away. Open one, break it, and watch the error name a line.

Blog feed

query + fragment

A paginated query with a variable for the page size, a directive on the author, and a fragment that three screens can share.

Store cart

mutation + input

A mutation that takes an input object, returns a cart and a list of user errors, and nests money three levels down.

Sign in

interface + inline fragments

An interface with two concrete types, split apart with inline fragments, next to a fragment on the interface itself.

Schema only

SDL

A whole schema in the definition language: descriptions, a union, an enum, an input type, a directive and an extension.

Four readers

The same tree, four times

The document is parsed once, into one tree. Each reader walks that tree for its own purpose, which is why the four answers never disagree.

What each reader does
Reader What it does File
Formatted Writes the tree back with two or four space indents, one field per line, arguments on one line until they get long, and comments where they were. .graphql
One line The same tree with no whitespace it does not need: for a URL, a log line or a query string. Comments are dropped. .graphql
TypeScript Reads the schema and writes interfaces, unions and enums. A nullable field says so, an optional input says so. .ts
Mock data Walks the query and the schema together and writes the JSON a server would answer with, aliases and list sizes included. .json

How it reads

Three things worth knowing

A formatter is only as good as its parser. These are the three decisions that decide whether the output feels right.

01

Whitespace and commas are not tokens

GraphQL ignores both, so the lexer throws them away and the printer decides them again. That is why a document typed on one line and the same document typed across twenty lines format to the same bytes.

02

Depth is not the same as size

Depth counts how many selection sets sit inside each other. Cost counts fields, and multiplies a list by its first or last argument. A shallow query on a list of ten is more expensive than a deep query on one object.

03

A mock is a promise, not a result

The mock follows the types: an object becomes an object, a list of three becomes three, an enum takes its first value. It says nothing about what a resolver will return, which is exactly what makes it useful in a test.

Questions

Does it validate my query against a real server?

No. Nothing is sent anywhere. The checker compares the document with the schema you paste, so it can find a field the schema does not define, a selection set on a scalar, a variable that was never declared or a fragment nobody spreads. It cannot know what a resolver returns at run time.

What does cost mean here?

One point per field. A field with a first, last or limit argument multiplies the fields under it by that number, capped at ten. It is the usual way to put a number on a query before it reaches a server, and the limit is a suggestion rather than a rule.

Why is a nullable field typed as a union with null?

In GraphQL a named type with no exclamation mark may be null. TypeScript has no other way to say that, so the generator writes the union. A required field has no union, and an input field that is optional or has a default gets a question mark.

Can it answer a query with no schema?

It can mock a shape from the selection set alone, guessing strings, numbers and booleans from field names, but it cannot know that a field returns an object rather than a scalar. Paste the schema for a mock that matches the types.

Which documents does it understand?

Queries, mutations, subscriptions, fragments, variables and directives, and the schema definition language with scalar, type, interface, union, enum, input, directive and extend. Comments are kept where the document allows them, and the formatter can be run on its own output again without changing it.

Is anything saved?

The document, the schema, the language and the theme are kept in this browser so the page opens where you left it. The content policy sets connect-src to none, so nothing leaves the tab.