Arguments, Mutations & Joins

Master filtering with variables, writing safely via @sideEffect mutations, resolving cross-branch joins in batches, and translating REST or Direct-MCP habits into clean GAP workflows.

What you'll learn

  • Pass typed GraphQL variables instead of string formatting so PlanCache reuses compiled query plans safely.
  • Distinguish query (read-only) from @sideEffect mutation calls gated by dry_run and Cedar two-person rules.
  • Map every REST / Direct-MCP concept you already know to its exact counterpart in GAP.
On this page

Arguments & Parameterized Variables (PlanCache Reuse)

Just like query parameters in a REST URL, GraphQL fields accept typed arguments such as customer(id: 1) or orders(customer_id: 1). Never concatenate user or LLM inputs directly into query text—declare strongly typed variables ($cid: Int!):

graphql Parameterized Query + Variables
query GetCustomerDossier($cid: Int!) {
  customer(id: $cid) { id name tier }
  orders(customer_id: $cid) { id status total_cents }
  customer_notes(customer_id: $cid)
}

# Variables JSON:
# { "cid": 1 }
  • Zero Injection: Typed variables prevent syntax smuggling inside query strings.
  • Hot Cache Hits: Because the query text stays identical across customers, GAP reuses the compiled plan in PlanCache keyed by (TenantId, snapshot_generation, query_hash) (INV-09).

Mutations & @sideEffect Safety Rails

While query operations read data cleanly across snapshots, state-changing actions must use mutation (or MCP tool gap_mutate) annotated with @sideEffect:

GAP @sideEffect levels from spec/02-gap-ql.md §5 and Cedar enforcement
SideEffectLevelMeaningDefault Cedar Policy Behavior
NONERead-only lookup with no state change.Permitted for authorized Read principals.
REVERSIBLEDraft update or compensating write (can undo).Allowed with Mutate permission; logged to BLAKE3 ledger.
IRREVERSIBLE / UNKNOWNPayment transfer, ledger delete, or unverified tool.Blocked unless context.approved && context.approverIsDifferent holds.
json MCP 2026-07-28 — Safe dry_run Preview via gap_mutate
{
  "jsonrpc": "2.0",
  "id": 10,
  "method": "tools/call",
  "params": {
    "name": "gap_mutate",
    "arguments": {
      "query": "mutation { issue_refund(order_id: 101) { ok } }",
      "dry_run": true
    }
  }
}

GAP for REST & Direct-MCP Developers (Translation Table)

You do not throw away your existing REST APIs or MCP servers to adopt GAP—you keep them running unchanged and mount them as declarative NGC branches.

Translating REST and Direct-MCP engineering habits to GAP
What You Know (REST / Direct-MCP)Exact GAP CounterpartKey Engineering Upgrade
Separate HTTP base URLs / multiple MCP configsSingle gateway URL (/graphql, /mcp, /ag-ui)One auth layer, TLS 1.3 QUIC transport, and snapshot boundary.
Fetching tools/list with 500 JSON schemasStatic 5 tools (651 tokens) + gap_describe / gap_searchCuts schema tax by 99% while hiding unauthorized ops (INV-05).
Writing client loops for id in ids: fetch(...)@join + OpenAPI x-gap-in-param DataLoader batchingDeduplicates keys into ceil(K/max_batch) calls (INV-18).
Hand-rolled regex ACLs before tool callsDeterministic Cedar rules (policies/default.cedar)Default-deny pure checks with two-person approval for risky writes.
Trusting upstream tool docstrings blindlyJCS BLAKE3 desc_hash pinning + <gap:untrusted>Freezes rug-pull mutations automatically into BranchStatus::Drift.
Going deeper: Why did GAP choose standard GraphQL instead of a brand-new query language?

Per GQL-001 and spec/02-gap-ql.md, inventing custom keywords like traverse would break every IDE highlighter, schema linter, and validation library. Using 100% standard GraphQL lets GAP validate queries with Apollo's Rust apollo-compiler, pass 136/136 differential conformance checks against graphql-js 16.13.2, and express federation cleanly with @join and @sideEffect directives. Ready to practice? Head to GAP Academy.