ARCHITECTURE GUIDE · PUBLISHED NOV 29, 2026

How ES6 Proxy-Based GraphQL Query Generation Works

Traditional GraphQL clients such as Apollo Client and Relay require developers to co-locate explicit gql query documents or fragments alongside UI components. Over time, refactored components often leave behind over-fetched fields that silently bloat network payloads. Proxy-based clients invert that workflow: the JavaScript runtime observes which properties your code actually touches and synthesizes the minimal GraphQL document automatically.

1. Two-Pass Selection Collection

When a component renders for the first time against an empty cache, every property access on the root query object invokes a JavaScript Proxy get trap:

  1. Pass 1 (Collection): Reading query.user({ id: '7' }).name records a selection path user(id:"7") { name } and returns a placeholder value (or suspends in Suspense mode).
  2. Batch Flush: At the end of the synchronous render tick, the scheduler merges all recorded paths into a single GraphQL operation and dispatches it via queryFetcher.
  3. Pass 2 (Resolution): The JSON response hydrates the normalized cache, triggering a single re-render where every property now returns real typed data.

2. Trade-Offs vs Static Query Compilers

DimensionProxy-Based (GQless)Static Compiler (Relay / Codegen)
Refactoring SpeedDelete a JSX field → immediately dropped from queryMust manually remove field from fragment & recompile
Persisted QueriesDynamic query strings (requires APQ hashing)Static query hashes known at build time
Conditional BranchesNested branches may trigger a second fetch unless prefetchedAll conditional fields declared upfront in one document

To get started with the runtime and schema generator, review the CLI Codegen guide and the Core Client API reference.