On this page
The short answerWhat goes stale in GraphQL docsExtract the examples firstGet a current schemaValidate documents against the schemaCatch deprecated usage and breaking changesRun the query, not just the validationTest the copies in your guidesKeep credentials out of the runRun it on every changeChecklist for a GraphQL example testWhere DocsAlive fitsWhat this does not replaceThe sources we checkedFAQGraphQL docs are full of queries, mutations and variable blocks. Each one is checked against the schema when a server receives it, so a field that was renamed or removed turns a documented query into an error the reader has to debug. This guide shows how to catch that before readers do: validate every documented operation against the current schema, then run the important ones and compare what comes back with what the docs promise.
The short answer
Test a GraphQL example in layers, because each layer catches a different failure. Extract every query, mutation and fragment from the docs into files a tool can read. Get the current schema, from the SDL file in the repo or by introspection against a test server. Validate the documents against that schema — the same validation a server runs before execution — and fail the run on any error, including use of deprecated fields. Then, for the examples readers actually build on, execute the operation against a test endpoint and compare the shape of the response with the sample response printed in the docs. Finally, test the copies: the same query usually lives in a quickstart, a tutorial and an SDK README as well as the API reference, and each copy drifts on its own schedule.
DocsAlive does not validate GraphQL documents against a schema. It reads the Markdown pages around the API — the guides, tutorials and READMEs where the same operations appear as code blocks — and runs those blocks in a fresh container. Keep the schema tooling described here for the schema itself, and use an execution check for the pages readers copy from. The API reference testing guide covers the rendered reference page, and the curl examples guide covers the command-line form of the same requests.
What goes stale in GraphQL docs
GraphQL schemas evolve in small steps, and each step can break a different part of the docs:
- Renamed or removed fields. The docs query a field the schema no longer has. This is the most common break, and validation catches it immediately.
- Changed argument types. A variable that was a
Stringis now anID, an optional argument became required, or an argument was removed. The query text still reads fine; it fails when it is checked against the schema or when its variables are coerced. - Deprecated usage. A documented query still works but relies on fields marked deprecated. It will break at the next schema cleanup, and readers are learning a pattern you are about to remove.
- Sample responses. The JSON shown under a query no longer matches the shape the query returns — fields were renamed, nested differently, or a list became a connection with edges and nodes.
- Fragment drift. A fragment defined in one guide is reused by name in another, and the two copies no longer agree, so an operation that validates in one page fails in the other.
None of these need a reader to find them. Every one is visible to a validator or a test run, which is the point of testing the examples instead of proofreading them.
Extract the examples first
Validation tools work on documents, so the first job is getting every documented operation into a file, unchanged. Pull each query, mutation, subscription and fragment out of the docs into its own .graphql file, keeping the operation name and the page it came from in the filename or a manifest. Keep fragments with the operations that use them, or in a shared folder every operation is validated with — an operation that spreads a fragment cannot be validated without the fragment's definition.
Do not tidy the examples as you extract them. If a documented query is missing a closing brace or uses a field that does not exist, that is the finding. Extraction that silently fixes the text produces a test suite that passes and docs that still fail for readers. Extract mechanically, validate what you extracted, and fix the docs — not the test copies — when something fails.
Get a current schema
Validation is only as good as the schema it runs against, and a stale schema is worse than none: it passes examples the live API rejects and fails examples the live API accepts. There are two reliable sources. The first is the schema definition in the API's own repository, as an SDL file or printed from the running code — use the version from the same branch the docs describe. The second is introspection: a GraphQL server can describe its own type system in response to an introspection query, so a test or staging endpoint can hand you exactly the schema it enforces.
Whichever source you use, record where the schema came from and when. When a validation run fails, the first question is whether the docs are wrong or the schema snapshot is old, and a run that cannot answer that question gets ignored. Refresh the schema in the same job that runs the validation, never as a manual step someone has to remember.
Validate documents against the schema
A GraphQL server parses each operation and then validates it against the type system before running it — the specification's Validation section describes this step, and a document that fails validation is not executed. You can run the same step offline, against every documented example, long before a reader does. GraphQL Inspector is one tool built for exactly this: its validate command takes the documents first and the schema second, checks the documents against the schema, and also reports use of deprecated fields:
npm install -g @graphql-inspector/cli
graphql-inspector validate './documents/*.graphql' schema.graphql
Run it so that any error fails the job, and print the file and the operation name with each failure. A validation error that scrolls past in a log is a broken example waiting for a reader. The failures you will see most are the stale cases above: fields that do not exist on a type, variables of the wrong type, required arguments that are missing, and fragments that are defined twice or not at all.
Validation proves an operation is well formed against the schema. It does not prove the operation does what the surrounding prose says it does, and it says nothing about the response. That is what the next two layers are for.
Catch deprecated usage and breaking changes
Two schema-side checks keep the docs ahead of the schema instead of behind it. The first is deprecated usage: because validate reports documents that rely on deprecated fields, a docs page that teaches a deprecated field fails the run while the field still works — which is when you want to know, not after the removal ships. Treat deprecated usage in docs as an error, not a warning, or it will still be there at removal time.
The second is the schema diff. When the schema changes, GraphQL Inspector's diff command compares the old and new schemas and marks each change breaking, dangerous or non-breaking:
graphql-inspector diff schema-old.graphql schema-new.graphql
A breaking change on that list — a removed field, a tightened type, a new required argument — is a list of docs pages to check before the release goes out. The same tool's coverage command reports how much of the schema your documents exercise, which shows the other gap: fields and types the API has but the docs never mention. Coverage gaps are not errors, but they are the cheapest map of undocumented surface you can get.
Run the query, not just the validation
Validation proves the operation is well formed. It does not prove it returns what the docs say it returns. Where a test endpoint exists, execute each documented operation with the documented variables and compare the response with the sample printed in the docs. Compare the shape, not the bytes: field names, nesting and types must match, while generated IDs, timestamps and paging cursors will differ between runs and should be masked out of the comparison.
Pay attention to the error cases the docs describe. If a guide says a query returns a specific error when a record does not exist, run that case too — error shapes drift just as data shapes do, and a reader following a troubleshooting page is the reader least able to improvise. Mutations deserve the same treatment as queries, run against a disposable data set: a documented mutation whose arguments changed will often still validate if the new argument is optional, and only an execution shows that it no longer does what the prose claims.
Keep this lane credentialed and separate, as the next section describes. Validation runs anywhere, on every change, with no secrets. Execution needs an endpoint and usually a token, so it runs where those are safe to use.
Test the copies in your guides
The reference is not the only place an operation lives. The quickstart shows the first query a new user runs. The tutorial builds a mutation up over three pages. The SDK README repeats both in a second language's syntax. Each copy was correct when it was pasted, and each one ages independently, so a schema change that the reference survives can still break the tutorial.
Extract and validate the copies the same way as the reference examples — the extraction step above does not care which page a code block came from. When a copy fails, fix the page, and check whether the same operation appears anywhere else. The documentation drift guide covers the general pattern: examples rarely live in one place, and testing only the canonical copy leaves the others to fail in front of readers.
Keep credentials out of the run
Docs examples love realistic tokens, and realistic tokens have a way of being real. Three rules keep the test lane safe. First, the validation lane needs no credentials at all — schema and documents are both files — so run it in the plainest CI job you have, with no secrets in the environment. Second, the execution lane uses a dedicated test account on a test endpoint, with a token stored in the CI secret store and scoped to that environment; a token copied from a developer's machine, or worse from the docs themselves, is a leak with extra steps. Third, scan the examples before you run them: if a documented query ships with a token, an email address or a production URL in it, that is a finding about the docs, and it should fail the run like any other error.
Run it on every change
- Pull requests: validate on every change to the docs or the schema. Validation is fast and needs no endpoint, so there is no reason for it to be rarer than the lint you already run.
- Releases: run the full set — validation, the schema diff against the previous release, and execution against the release candidate — before the new schema is announced, so the docs and the API change in the same step.
- Nightly: run validation and execution against the live schema even when nobody touched the docs. Schemas change under docs that nobody edited, and the nightly run is what catches drift from the API side.
Whichever cadence you choose, the failure has to reach a person. A failing docs test that only colours a dashboard red will be failing, unread, on the day a reader finds the same break by hand.
Checklist for a GraphQL example test
- Every query, mutation and fragment extracted from the docs, unchanged, with its source page recorded.
- Schema taken from the current branch or by introspection, refreshed in the same job that validates.
- Validation run over all documents; any error fails the job and names the file and operation.
- Deprecated field usage treated as an error, not a warning.
- Schema diff checked on every schema change; breaking changes matched against the docs before release.
- Key operations executed against a test endpoint; response shape compared with the documented sample, volatile values masked.
- Documented error cases executed, not just the happy path.
- Copies in quickstarts, tutorials and READMEs extracted and validated too.
- No real credentials in any example, and the execution lane uses a scoped test token.
Where DocsAlive fits
The checks above cover the schema and the reference. They do not cover the pages around them — the quickstart whose first query is the one every new user runs, the tutorial whose mutation spans three pages, the README in each SDK repo. Those pages are Markdown, and their code blocks are where readers actually copy from. DocsAlive runs the code samples in your docs in a clean sandbox and reports what breaks: it installs DocsAlive as a GitHub App, runs the blocks, and opens fix PRs that a human approves. A free health check runs the samples on up to 40 pages of a public repo and sends a report within 2 business days — the quickest way to see where the copies in your guides stand. The docs testing checklist puts this execution layer next to the rest of the pre-release checks.
What this does not replace
Schema validation does not test the API itself: resolvers, permissions and performance belong to the API's own test suite, and an operation can validate, execute and still be the wrong operation to teach. Execution testing of examples does not replace contract testing between services. And none of this checks the prose — a guide can have perfectly valid examples and still explain them badly. What these checks remove is the specific, common failure where the docs show an operation the schema no longer accepts, and they remove it before a reader finds it.
The sources we checked
| Source | What it covers |
|---|---|
| GraphQL specification | The validation step: documents are checked against the type system before execution |
| GraphQL Inspector documentation and README | The validate, diff and coverage commands, their argument order, and deprecated-usage reporting |
| DocsAlive product pages | What the health check runs, the GitHub App, and human-approved fix PRs |
FAQ
Is a valid operation enough?
No. Validation means the operation agrees with the schema. It can still return a different shape from the sample response in the docs, rely on a deprecated field, or be the wrong example for the task the page describes. Validation, deprecated-usage checks and an execution run answer those separate questions.
My docs generate the reference from the schema. Do I still need this?
The generated reference inherits the schema's correctness, but the handwritten pages around it — quickstarts, tutorials, migration guides — do not, and generated references still ship sample responses and example operations that can go stale. Test the handwritten copies at minimum.
Should sample responses be compared byte for byte?
Usually not. IDs, timestamps and cursors change between runs. Compare status, field names, nesting and types, mask the volatile values, and treat any field the docs promise but the response omits as a failure.




