Skip to content

fix(api): validate the whole selection set against the schema - #134

Merged
v1rtl merged 3 commits into
stagingfrom
fix/reject-unknown-output-fields
Sep 30, 2026
Merged

v1rtl merged 3 commits into
stagingfrom
fix/reject-unknown-output-fields

Conversation

@v1rtl

@v1rtl v1rtl commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #132. The nested-argument check needs #132's declarations (subdomains(first, skip), Account.domains(first, skip)). Merge #132 first; this PR's base will then move to staging.

An unknown field in a selection set resolved to null, which looks exactly like a value that is genuinely absent:

{ domains(first:1){ notARealField } }  →  {"data":{"domains":[{"notARealField":null}]}}

Arguments were checked only on root fields. { domains(where:{bogus:1}) } was a 400, but the same typo one level down silently dropped the filter.

Changes

Declare what is served first (4e9fa62). An audit of every builder and hand-written serializer against schema.graphql found these served but undeclared. Without this commit, strict validation would have turned working queries into whole-response errors, and no golden selected them.

  • Domain.namehash, Domain.domain, Domain.subdomainConnection(first), Domain.eventsConnection(first). The connections are declared with only the first they honour (max 100) and no after, which they never supported; the descriptions point to the real pagers.
  • Registration.block, .blockNumber, .timestamp.
  • ResolverDetail: the 17 Resolver fields that resolver(id:) / resolversByOwner serve by delegating to the per-name builder at the zero node. On record-model resolvers that is the resolver-wide default record, so some return real data; the descriptions say so.
  • Everything else matches: the event payload types, RegistryInfo, connections, coverage/finality, _meta, roles, approvals and metadata. Nested argument reads match their declarations too.

Validate the whole document (44a131f). The validator now walks every operation at every depth, through named, inline and root-level fragments. It rejects:

  • unknown fields
  • unknown or missing arguments at any depth (`Domain.subdomains` has no argument `bogus`)
  • unknown input-object fields, including inside lists (where: { or: [ … ] })
  • fragments whose type condition is not the enclosing type (the schema has no interfaces or unions)

It also:

  • walks each named fragment once per operation
  • builds lookup keys on the stack instead of allocating per selection
  • fixes a false rejection: a root-level fragment named after a root field used to trip that field's required-argument check
  • leaves unknown root fields to the executor's existing UnknownRootField error

Inline fragments (b785d70)

  • The parser encoded ... on T { … } as a field named T, so validation had to guess from the name. An empty inline fragment was wrongly rejected, and the first interface added would have broken the guess.
  • The executor also resolved it as a field ("Domain": null).
  • Inline fragments are now flagged explicitly. The executor splices them in like named fragments, and complexity charges them at the spread's depth.

Behaviour changes for clients

  • Unknown selection fields, and unknown arguments or input fields below the root, are now VALIDATION_ERROR instead of null or silently ignored.
    • This includes skip on Domain.events and on the nested connections: they parse it but have never applied it.
  • ... on Domain { labelName } now returns labelName instead of "Domain": null.

Tests

  • Validator unit tests cover:
    • unknown fields and arguments at depth
    • nested required arguments
    • input objects in lists
    • root fragments, and a fragment named after a root field
    • wrong and unknown type conditions
    • empty inline fragments
    • an overlong field name
  • Conformance: new error ops for each rejection, plus positive ops that select every newly declared field on real fixture data.
  • Apart from the intended ok_typename_and_fragments change (the inline fragment now resolves), no existing golden changed, so no current conformance query is newly rejected.

Known, not fixed here

  • Selection ignored by payloads. The nested connections emit pageInfo and cursor whether or not they are selected, and the asX event payloads emit every key.
  • Partial filter on nested events. Domain.events(where:) honours only part of EventFilter (type, type_in, contractAddress, block/timestamp bounds). Other declared filter fields validate but are ignored.

zig build test-all: 89/89 steps, 1493/1493 tests (zig 0.16.0). All three PRs also merge cleanly together onto staging and pass test-all combined.

…field

The parser encoded `... on T { … }` as a field named T with nothing to
tell it apart from a real field, so the executor resolved it as an
unknown field ("Domain": null) and every consumer had to guess from the
name. Mark inline fragments explicitly; the executor splices their
selections in like a named fragment, and complexity charges them at the
spread's depth like one.
Served with real handlers but absent from schema.graphql, so invisible
to introspection and about to become hard errors once selections are
validated:

- Domain.namehash, Domain.domain, Domain.subdomainConnection(first),
  Domain.eventsConnection(first)
- Registration.block, Registration.blockNumber, Registration.timestamp
- ResolverDetail: the 17 Resolver fields resolver(id:) and
  resolversByOwner serve by delegating to the per-name builder at the
  zero node (the resolver-wide default record on record-model resolvers)

The nested connections are declared with the `first` they honour and
no `after`, which they have never supported.
An unknown field in a selection set resolved to null, indistinguishable
from a genuine absence, and arguments were only checked on root fields:
{ domains(where:{bogus:1}) } was a 400 while the same typo one level
down silently dropped the filter.

The validator now walks every operation at every depth, through named,
inline and root-level fragments, and rejects unknown fields, unknown or
missing arguments and unknown input-object fields (including inside
lists) wherever they appear. Fragment type conditions must name the
enclosing type, since the schema has no interfaces or unions. Named
fragments are walked once per operation, and keys are built on the
stack instead of allocated per selection.

Also fixes a false rejection: a fragment spread at the root named after
a root field was validated as that field and failed its required-arg
check. Unknown root fields keep the executor's UnknownRootField.
@v1rtl
v1rtl force-pushed the fix/reject-unknown-output-fields branch from d2e4592 to 44a131f Compare September 29, 2026 13:56
@v1rtl v1rtl changed the title fix(api): reject unknown fields in a selection set instead of resolving them to null fix(api): validate the whole selection set against the schema Sep 29, 2026
@v1rtl
v1rtl changed the base branch from staging to fix/subdomains-pagination September 29, 2026 13:57
Base automatically changed from fix/subdomains-pagination to staging September 29, 2026 14:59
@v1rtl
v1rtl merged commit 8d33956 into staging Sep 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant