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
variablesinstead of string formatting soPlanCachereuses compiled query plans safely. - Distinguish
query(read-only) from@sideEffectmutationcalls gated bydry_runand 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!):
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
PlanCachekeyed 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:
| SideEffectLevel | Meaning | Default Cedar Policy Behavior |
|---|---|---|
NONE | Read-only lookup with no state change. | Permitted for authorized Read principals. |
REVERSIBLE | Draft update or compensating write (can undo). | Allowed with Mutate permission; logged to BLAKE3 ledger. |
IRREVERSIBLE / UNKNOWN | Payment transfer, ledger delete, or unverified tool. | Blocked unless context.approved && context.approverIsDifferent holds. |
{
"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.
| What You Know (REST / Direct-MCP) | Exact GAP Counterpart | Key Engineering Upgrade |
|---|---|---|
| Separate HTTP base URLs / multiple MCP configs | Single gateway URL (/graphql, /mcp, /ag-ui) | One auth layer, TLS 1.3 QUIC transport, and snapshot boundary. |
Fetching tools/list with 500 JSON schemas | Static 5 tools (651 tokens) + gap_describe / gap_search | Cuts 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 batching | Deduplicates keys into ceil(K/max_batch) calls (INV-18). |
| Hand-rolled regex ACLs before tool calls | Deterministic Cedar rules (policies/default.cedar) | Default-deny pure checks with two-person approval for risky writes. |
| Trusting upstream tool docstrings blindly | JCS 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.