Review GraphQL Queries Against a Local Schema with REA
On this page
A client query says hero, but the schema has no field with that name. Before searching for a missing resolver, check whether hero is an alias. Then follow the nested fields and fragment spreads to the declarations they actually reference.
This walkthrough reviews a small query against the published SWAPI schema. We use REA to locate field bindings, deliberately introduce a misspelled field and a missing fragment, and finish with a separate validation pass. No request is sent to the SWAPI service.
We tested REA 6.10.1, Node.js 26.12.1, Python 3.14 and Bun 1.3.14 on macOS arm64. REA requires Node ^22.23.4 || ^24.22.1 || >=26.12.1. The commands assume rea --version reports 6.10.1; see the setup guide if needed.
Keep the schema tied to real source bytes
Use the unchanged SWAPI SDL retained in REA’s versioned fixtures. Its provenance record identifies the upstream revision and MIT license. This is a published application’s schema, not one invented to make the example pass.
mkdir graphql-review
cd graphql-review
curl -fL --retry 2 --connect-timeout 10 --max-time 30 --output swapi.graphql \
https://raw.githubusercontent.com/morluto/rea/rea-agents-6.10.1/tests/fixtures/graphql/swapi.graphql.txt
shasum -a 256 swapi.graphql
The file is 35,868 bytes, with SHA-256 ebc4d09b21e2aec2735d6f0d3c812fc017cd49a44900dd3ae34f49f6f8c25133. Keep this copy with the query and results. A local schema can be older than a deployed API; a matching field here does not establish what the server currently implements.
Write a query with an alias and a fragment
The following operation document is ours. It asks for one person and one film, using names that exist in the real SDL. $personID is a declared variable; we never supply it to a server or execute the operation.
cat > review.graphql <<'GRAPHQL'
query Review($personID: ID!) {
hero: person(personID: $personID) {
__typename
name
homeworld { name }
}
film(filmID: "1") { ...FilmCard }
}
fragment FilmCard on Film {
title
releaseDate
}
GRAPHQL
rea inspect-api-contract swapi.graphql --contract-format graphql-sdl \
--operations-path review.graphql --json > complete.json
Use --contract-format graphql-sdl: the command otherwise defaults to OpenAPI JSON. --operations-path supplies the separate client document. In this run the result has 53 types, 243 fields, two definitions, eight field references and one fragment spread.
Those eight references include the two fields inside FilmCard. A spread is recorded separately from field references. Do not count a fragment name as another selected field.
Follow the alias to its schema field
The complete JSON contains both declarations and references. Join a reference’s schema_field_id to the corresponding fields record to find its declaration:
python3 - <<'PYCODE'
import json
r = json.load(open('complete.json'))['normalized_result']
fields = {f['field_id']: f for f in r['fields']}
print(r['summary'])
for ref in r['references']:
field = fields.get(ref['schema_field_id'])
declaration = field['field_key'] if field else '(no SDL declaration)'
print(ref['response_key'], ref['field_name'], ref['state'], declaration,
'query line', ref['source']['line'])
PYCODE
The hero response key resolves to field person on type Root, with result type Person. The actual query root is named Root, not Query. The alias changes the response key; it does not rename the schema field.
The two name selections bind to different declarations: Person.name and Planet.name. Their parent-reference links distinguish the nested paths. Searching only for the text name would miss that distinction.
__typename has state model-only, reason no-sdl-source, result type String!, and no schema_field_id. GraphQL supplies this field through its model; it is not a missing declaration in the downloaded SDL. The other seven references are resolved.
Every reference retains its query location, while the joined declaration retains its schema location. REA reports line/column plus UTF-16 text offsets. Those offsets address decoded text, not UTF-8 byte positions; use the document role and hash when opening the relevant file.
Read fragment links without inventing execution order
python3 - <<'PYCODE'
import json
r = json.load(open('complete.json'))['normalized_result']
for spread in r['fragment_spreads']:
print(spread['name'], spread['state'], spread['matching_definitions'])
target = next(d for d in r['definitions']
if d['definition_id'] == spread['target_definition_id'])
print(target)
PYCODE
The spread named FilmCard is resolved and has one matching definition. Its target is the separate fragment definition on Film. The fragment’s title and releaseDate references bind in that declared type scope.
REA records the definition and spread relationship rather than recursively copying fragment fields into every use site. This is useful when a shared fragment appears in several operations. It does not establish whether every spread is applicable at runtime, whether a branch will be reached, or what data the server will return.
Make unknown fields and missing fragments visible
Create two modified documents while keeping the original query intact. The first replaces the person’s name with nmae and changes the spread to an undefined fragment. The second changes only an argument name.
python3 - <<'PYCODE'
from pathlib import Path
query = Path('review.graphql').read_text()
Path('unknown.graphql').write_text(
query.replace(' name\n', ' nmae\n')
.replace('...FilmCard', '...MissingCard'))
Path('bad-argument.graphql').write_text(
query.replace('personID: $personID', 'unknownArgument: $personID'))
PYCODE
rea inspect-api-contract swapi.graphql --contract-format graphql-sdl \
--operations-path unknown.graphql --json > unknown.json
rea inspect-api-contract swapi.graphql --contract-format graphql-sdl \
--operations-path bad-argument.graphql --json > bad-argument.json
python3 - <<'PYCODE'
import json
for name in ['unknown', 'bad-argument']:
r = json.load(open(name + '.json'))['normalized_result']
print(name, r['summary'], r['source_coverage'])
for ref in r['references']:
if ref['state'] == 'unknown':
print(ref['field_name'], ref['reason'], ref['source'])
for spread in r['fragment_spreads']:
print(spread['name'], spread['state'])
PYCODE
The unknown result still retains the schema and query declarations. It reports one unknown reference, one unresolved spread and partial source coverage. nmae has reason unknown-field at query line four; MissingCard has spread state missing. These are controlled mistakes, not claims about the original SWAPI application.
The unused FilmCard definition remains in the document, so its two fields are still inventoried. Do not treat those fields as proof that the missing spread found a replacement, or that the fragment is reachable.
The argument-only variant is the more revealing control: all field bindings still resolve, source coverage says complete-within-scope, and REA reports zero diagnostics. The request is nevertheless invalid. The explicit operation_validation: field-resolution-only scope explains why.
Run full operation validation as a separate step
REA’s reader uses GraphQL.js 17.1.0 in this run. For a separate operation validation pass, install that same version in this disposable directory and call its validate API. This is a different check using the same library, not an independent parser implementation.
bun add --exact [email protected]
cat > validate.mjs <<'JS'
import {readFileSync} from 'node:fs';
import {buildSchema, parse, validate} from 'graphql';
const schema = buildSchema(readFileSync('swapi.graphql', 'utf8'));
for (const name of ['review', 'unknown', 'bad-argument']) {
const document = parse(readFileSync(`${name}.graphql`, 'utf8'));
console.log(name, validate(schema, document).map(error => error.message));
}
JS
node validate.mjs
The original review document returns an empty error list. The unknown document reports that Person.nmae does not exist, MissingCard is unknown, and FilmCard is unused. The bad-argument document reports Unknown argument "unknownArgument" on field "Root.person".
That last comparison is why a clean REA field inventory should not become a blanket “valid query” conclusion. Arguments, directive behavior and whole-operation validity are outside this reader’s field-binding profile. A full validator still does not contact a resolver, enforce the service’s authorization rules or verify returned values.
Hand off the query, bindings and limits together
Keep both source files, their SHA-256 values, the REA version, complete inspection JSON and validation results. The schema and operation are independently identified snapshots, not an atomic capture of a running service. Preserve the exact pair used in the review.
Use the reference-to-declaration links to explain which schema field a client actually selects. Use the validation result to explain whether the supplied document satisfies the schema’s rules. Use captured traffic or a separately authorized runtime test for questions about actual service behavior. The HAR guide covers that different evidence source.
For method/path inventories rather than GraphQL field bindings, see the OpenAPI walkthrough.
Sources: REA 6.10.1 API contract reader, versioned SWAPI fixture provenance, and GraphQL validation.