GAP-QL & Batched Joins
GAP-QL compiles strictly valid GraphQL parsed by apollo-compiler and eliminates N+1 client round-trips with bounded DataLoader key batching (INV-18).
What you'll learn
- Why modeling discovery as
__metaGraph/__search/__typepreserves GraphQL parser compatibility. - How GAP deduplicates join keys to dispatch
ceil(unique_keys / max_batch)upstream calls (INV-18). - Full
GAP-Benchtoken matrix acrossN in {10, 50, 200, 1000}.
On this page
Zero Custom Keywords (GQL-001)
Instead of inventing non-standard GraphQL syntax like traverse { ... }, GAP exposes discovery and federation via standard schema root fields and validated directives from spec/02-gap-ql.md §5 (@join, @sideEffect, @auth, @pii). Every query passes apollo-compiler validation and differential testing against graphql-js 16.13.2.
directive @join(to: String!, on: [JoinKey!]!, cardinality: Cardinality!,
strategy: JoinStrategy = FOREACH_BATCH, status: JoinStatus = PROPOSED,
evidence: JSON) on FIELD_DEFINITION
directive @sideEffect(level: SideEffectLevel!, idempotent: Boolean = false, dryRun: Boolean = false) on FIELD_DEFINITION
directive @auth(policy: String, scopes: [String!]) on OBJECT | FIELD_DEFINITION
directive @pii(kind: String!) on FIELD_DEFINITION
Preventing N+1 Waterfalls (INV-18)
Suppose a cross-branch query fetches 50 customers and joins their notes from an external MCP or SQL branch. Flat RPC loops fire 50 separate network requests. GAP extracts unique keys, enforces bounded chunks, and sends at most ceil(unique_keys / max_batch) BatchQuery frames—validated on every CI run (VER-040).
Join N=1,000 · GAP BatchJoin
Code Graph (24) · GAP AST
Visual bar comparison (min-width clamped for clarity on log-scale ratios).
| Suite / Scale N | Direct-MCP (Uncached) | GAP (Uncached) | Direct-MCP (Cached) | GAP (Cached) | Turns (Direct -> GAP) |
|---|---|---|---|---|---|
cross_branch_join · N=10 | 8,891.8 | 8,517.9 | 2,200.5 | 7,383.7 | 4 -> 2 |
cross_branch_join · N=50 | 41,539.8 | 8,547.9 | 6,740.7 | 7,413.7 | 4 -> 2 |
cross_branch_join · N=200 | 163,619.8 | 8,547.9 | 23,717.4 | 7,413.7 | 4 -> 2 |
cross_branch_join · N=1,000 | 814,959.8 | 8,547.9 (-99.0%) | 114,294.4 | 7,413.7 (-93.5%) | 4 -> 2 |
code_graph · 24 symbols | 141,681.3 | 1,187.4 (119.3x) | 137,810.4 | 660.4 (208.7x) | 11 -> 1 |