Skip to content

Agent package, slice 3: query validator - #108

Merged
joadan merged 1 commit into
mainfrom
agent-ai-validator
Oct 15, 2026
Merged

joadan merged 1 commit into
mainfrom
agent-ai-validator

Conversation

@joadan

@joadan joadan commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Third slice of the agent package described in docs/design/agent-mode.md: every query the agent writes is checked against the scoped schema before it is sent.

Changes

Validator (QueryValidator, internal)

  • Document: exactly one operation, which must be a query; no schema definitions; clear syntax errors.
  • Selections: only allowed roots; fields that exist and aren't omitted; no selection on leaf fields and a required selection on object fields; aliases ignored, since the check uses real field names; fragments and inline fragments followed through their type conditions, including interfaces, with undefined and self-spreading fragments caught.
  • Arguments and values: unknown and missing required arguments, filter objects field by field, enum values, scalar kinds, null into non-null.
  • Variables: declared, with a type that is in scope and matches where it is used. Variable values are checked too, so an omitted field cannot be passed in through a variable.
  • Blocked: introspection (__schema, __type) and directives other than @include and @skip.
  • All errors are returned at once, each with a path and a fix: available names, "did you mean" suggestions, the paging pattern for paged fields, example selections, and enum values without quotes.

Design doc: slice status, and the note that variable values are validated.

Testing

  • 267 tests pass, 26 new (QueryValidatorTests):
    • Every query the validator accepts is also run against the in-process test server and must succeed, so the validator cannot be more lenient than the server.
    • An omitted field cannot be reached by selecting it, filtering on it as a literal, filtering on it through a variable, or sorting on it.
    • Variables, arguments, enums, fragments, document rules, and all errors reported at once.

Third slice of the agent package (docs/design/agent-mode.md): every query the
agent writes is checked against the scoped schema before it is sent.

It checks the document (one query operation, no schema definitions), allowed
roots, fields that exist and aren't omitted, leaf and object selections,
fragments and inline fragments through their type conditions, arguments, input
objects including filters, enum values, scalar kinds and variables. Variable
values are checked too, so an omitted field cannot be passed in through a
variable. Introspection and directives other than @include and @Skip are
blocked. All errors are returned at once with a path and a fix: available
names, "did you mean" suggestions, and the paging pattern for paged fields.

Every query the validator accepts in the tests is also run against the test
server, so the validator cannot be more lenient than the server.
@joadan
joadan merged commit 6cb9498 into main Oct 15, 2026
2 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