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/__type preserves GraphQL parser compatibility.
  • How GAP deduplicates join keys to dispatch ceil(unique_keys / max_batch) upstream calls (INV-18).
  • Full GAP-Bench token matrix across N 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.

graphql spec/02-gap-ql.md §5 — Built-in Directives
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).

LLM N+1 Waterfall vs GAP DataLoader BatchJoin (INV-18) Direct-MCP: N+1 Loop (4 turns · 814,959 tok) LLM calls customers -> receives 50 IDs Agent fires 50 sequential HTTP calls GAP @join: BatchJoin (2 turns · 8,547 tok) gap-exec deduplicates keys {1..50} ceil(unique_keys / max_batch) BatchQuery (INV-18)
LLM N+1 Waterfall vs GAP DataLoader BatchJoin (INV-18)
GAP-Bench Total Workload Tokens (Uncached Join & Cached Code Graph) Measured against Direct-MCP across multi-turn joins and AST code navigation
Join N=1,000 · Direct-MCP 814,959.8 tok (4 turns)
Join N=1,000 · GAP BatchJoin 8,547.9 tok (-99.0% · 2 turns)
Code Graph (24) · Direct-MCP 137,810.4 tok (11 turns)
Code Graph (24) · GAP AST 660.4 tok (208.7x · 1 turn)

Visual bar comparison (min-width clamped for clarity on log-scale ratios).

GAP-Bench Measured Tokens (Uncached vs 0.10x Prompt Cache, N=10..1,000)
Suite / Scale NDirect-MCP (Uncached)GAP (Uncached)Direct-MCP (Cached)GAP (Cached)Turns (Direct -> GAP)
cross_branch_join · N=108,891.88,517.92,200.57,383.74 -> 2
cross_branch_join · N=5041,539.88,547.96,740.77,413.74 -> 2
cross_branch_join · N=200163,619.88,547.923,717.47,413.74 -> 2
cross_branch_join · N=1,000814,959.88,547.9 (-99.0%)114,294.47,413.7 (-93.5%)4 -> 2
code_graph · 24 symbols141,681.31,187.4 (119.3x)137,810.4660.4 (208.7x)11 -> 1