Skip to content

feat(api-contract): inspect local GraphQL SDL and field references - #9140

Merged
gensokyo-dev merged 2 commits into
mainfrom
feat/8702-graphql-contract
Nov 6, 2026
Merged

gensokyo-dev merged 2 commits into
mainfrom
feat/8702-graphql-contract

Conversation

@gensokyo-dev

@gensokyo-dev gensokyo-dev commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Extends inspect_api_contract so an analyst can inspect local GraphQL SDL and bind operation selections to supplied field declarations without contacting endpoints. Refs #8702; this delivers the local SDL/operation slice, leaving introspection and version comparison open.

Problem and expected behavior

Previously the shared importer supported OpenAPI JSON only. format: "graphql-sdl" now returns type/field occurrences, operation/fragment owners, field references and explicit fragment-spread edges, with summaries and selected pages instead of requiring a full schema in agent context.

Change and scope

  • One shared application import serves CLI/MCP. GraphQL.js 17.1.0 owns syntax/model interpretation and loads only for the SDL profile; existing stable-file/resource ownership is reused.
  • Six graphql-contract collections support exact batch filters, fields and paging. Identity/source and applicable unknown reasons survive projection; retained pages reuse immutable facts without reopening inputs.
  • Bindings preserve aliases, wrappers, extension occurrences, parent relationships and precise SDL links. Missing/ambiguous fragments and unavailable schema models remain explicit. Fragments are visited once and linked, without recursive expansion. Field binding yields every 128 parsed output selections, including within a single wide definition; native SDK parsing/model construction remain synchronous within admission limits.
  • Full schema/operation validity, directive/argument behavior, introspection, federation composition, execution, diff and authorization are outside this profile. Parser/fact allowances and coverage are documented.

Contract and boundary impact

  • Owner: domain/apiContract produces facts; ApiContractService and the existing view projector share them across adapters. The cooperative driver preserves partial facts on cancellation and completed Evidence on late abort.
  • Scope/authority: offline parsing of caller-selected files, within the existing application capability; no execution/injection/protection-recovery decision is required.
  • CLI/MCP: CLI adds --contractFormat graphql-sdl and optional --operationsPath; MCP adds the SDL format/optional operations_path. Existing OpenAPI defaults and identities are preserved. The existing root-discriminator presentation preserves format/argument constraints after SDK conversion.
  • Evidence: document digests, UTF-16 ranges, token line/column and explicit coverage accompany facts. Files are independent snapshots, not an atomic pair. Optional caller_input_paths preserves auxiliary CLI spelling outside semantic identity. Parser failures retain queryable Evidence when recording succeeds. Evidence owns metadata equality for explicit duplicate-bundle imports; all same-invocation summary publishers preserve auxiliary paths.
  • Resources: existing artifact leases/cleanup and retention bounds; 32 MiB per document and conservatively charged facts, heap admission, public parser token/comment allowances and AST traversal admission. No target process or new provider setup.
  • Generated/package: one locked runtime dependency plus integrity-verified license notices; ignored catalogs/skills regenerated through standard commands. No binaries/build outputs committed.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a target process.
  • Inject instrumentation or run target scripts/code.
  • Write files only through the existing caller-selected Evidence publication/export workflow.
  • Contact network services during analysis.
  • Recover protected code or work around protections.

Evidence and regression coverage

  • Unmodified published SWAPI SDL: 53 types/243 fields, with pinned provenance and MIT license in tests/fixtures/graphql/. Public CLI/MCP tests cover advertised schema rejection, aliases/source bindings, selected/complete parity, Unicode/relative input spellings, source-free retained paging and bundle replay.
  • Published GitHub SDL (retrieved 2026-11-06): 1,824 types/8,426 fields; SHA-256 0d71ca68a4e951599b2ea541a81cc259a843608fc22b8eb1713a1d03551b149e, from https://docs.github.com/public/fpt/schema.docs.graphql. An independent source-line inventory checks every type/field name, owner and enclosing source span; selected operations additionally check expected field bindings. All field pages reconstruct the complete inventory.
  • Duplicate/missing definitions, model-only/unknown references, malformed primary/auxiliary documents, UTF-8/BOM positions, fact/file/depth allowances, cooperative/late cancellation and cleanup/path preservation have regression coverage.
  • A large complete MCP reply is deliberately refused by the default 10 MiB transport budget; the same continuing session successfully exports complete Evidence. Selected replies and later queries work without either input file. The budget is not raised.

For evidence-bearing changes:

  • Observations and derived field bindings remain distinguishable; runtime behavior stays unknown.
  • Artifact identity, provenance and failed attempts remain preserved.
  • Incomplete/unavailable facts remain explicit independently of page exhaustion.

Validation performed

  • Initial source/API/Evidence and sibling schema regressions: 107 passed across 8 files. After the review fixes, 100 affected source tests passed across 6 files, including query/fragment cancellation, full-SDK scope comparison, duplicate metadata import and tool-effect wording checks. The two review regressions fail before their producing-boundary fixes and pass after.
  • Public GraphQL CLI/MCP: 3 passed after review fixes; existing OpenAPI public flows: 3 passed; cleanup/caller-path boundary: 3 passed; Evidence bundle filesystem boundary: 50 passed; product catalog: 10 passed.
  • Full typecheck, module-boundary and architecture guards, focused lint/typed lint, production Knip: passed (focused lint retains only four existing warnings).
  • Runtime build, docs:build, docs:check (including README consistency), license checks and changed-file format checks: passed. CI 42212592906 passed on 41e514e: 24,415 source tests passed / 16 skipped, all 8 portable shards passed, static/build/docs and enabled platform checks (including Windows) passed. All three CodeQL analyses passed.

Measured real workflow: 64.709 s elapsed, 65.396 CPU s, 1.35 GiB peak sampled process-family RSS (200 ms sampling, 2 CPU affinity, 4 GiB guard; no resource stop). Warm selected-query medians: 1735.00 ms with reimport, 42.34 ms from retained facts. The same 10-row reply is 20,507 serialized bytes. Local profile base: 1f6dea30d plus the review fixes; its exact modified-source hashes match the rebased committed files.

The task includes SDK discovery/validation, repeats, all field pages and fresh CLI controls. OS caches are warm; model tokens/reasoning and cold-disk costs are unmeasured. The verification client alone uses --no-maglev with a 1 GiB heap for the pre-existing SDK/Node24 issue recorded in #9127; server/CLI use normal JIT. Default-JIT public workflows pass separately. These are measured selected-query workflows, not a universal speedup claim.

Compatibility, safety, and release

No migration for existing OpenAPI calls. Local verification is Linux/Node 24.22.1; it establishes offline parsing and public adapter behavior, not runtime API/server or native-provider behavior. GraphQL's dependency and fixture licenses are preserved. Analysis performs no network requests and does not modify input bytes.

Author readiness

Human owner: @gensokyo-dev (author exempt under CONTRIBUTING.md; human declarations remain unchecked).

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-06T11:22:07.403414Z
We couldn’t complete this review. Comment @codex review to try again.
1f6dea3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: plus

[Medium impact] The change adds a bounded local GraphQL analysis workflow to shared API contract tools.

The caller-path preservation requirement must be satisfied before merging; smaller operation-walk steps are a non-blocking improvement.

Findings

  1. P2 Auxiliary path updates disappear ▶
  2. P2 Large queries delay cancellation ▶
Fix with agent prompt
### Issue 1
src/domain/evidence.ts:104-108
The new `caller_input_paths` field is ignored when importing an otherwise duplicate bundle. Two CLI runs can use the same primary spelling but different equivalent spellings for `operations_path`, leaving their Evidence IDs unchanged. `EvidenceLedger.import` compares only `subject.name`, `subject.local_path`, and `caller_input_path`, so the second import silently keeps the old auxiliary spelling.

The repository requires preserving caller-selected paths and metadata. Include `caller_input_paths` in the ledger's metadata comparison and test repeated imports. This requirement must be satisfied before merging.

### Issue 2
src/domain/apiContract/GraphqlOperationFacts.ts:163-169
`collectGraphqlOperationFacts` yields between definitions, but `visit(definition)` walks each entire body synchronously. One query or fragment with thousands of sibling selections performs all field binding, hashing, and fact accounting before yielding again. Queued cancellation and other MCP requests must wait for that whole body.

Walk selections in bounded chunks, like the schema-field collector, rather than using definition size as the cooperative step.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds offline GraphQL SDL inspection and optional operation-to-field bindings through the shared CLI/MCP workflow.

  • Local GraphQL files produce source-linked declarations and field references.
  • GraphQL contract facts can be filtered and paged from retained Evidence.
  • CLI and MCP callers can select the GraphQL SDL profile and its operations file.

Scope acknowledged by gensokyo-dev: full operation validity, argument/directive behavior, introspection, and version comparison remain excluded or deferred.

Review used source inspection; tests were not run. Superseded status could not be checked because GitHub authentication was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  CLI[CLI] --> Service[Shared API contract service]
  MCP[MCP] --> Service
  Service --> Files[Verified local file snapshots]
  Files --> Parser[GraphQL parser and schema model]
  Parser --> Facts[Declarations and field bindings]
  Facts --> Evidence[Complete or partial Evidence]
  Evidence --> Bundle[CLI bundle]
  Evidence --> Retained[Session-retained facts]
  Retained --> Views[Summary and selected pages]
Loading

Reviews (1) · Last reviewed commit: "feat(api-contract): inspect local GraphQ..." · Reviewed by Greptile

Comment thread src/domain/evidence.ts Resolved
@gensokyo-dev
gensokyo-dev force-pushed the feat/8702-graphql-contract branch from 1f6dea3 to 41e514e Compare November 6, 2026 11:45
@gensokyo-dev
gensokyo-dev merged commit 5303199 into main Nov 6, 2026
56 of 58 checks passed
@gensokyo-dev
gensokyo-dev deleted the feat/8702-graphql-contract branch November 6, 2026 12:16
@morluto morluto mentioned this pull request Nov 11, 2026
3 tasks done
@morluto morluto added area: domain Domain logic, errors, and pure functions enhancement New feature or request labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants