Core Client API & Selection Cache
The core client exposes a typed query and mutation proxy tree backed by an in-memory normalized cache. Whenever application code reads a property such as query.project({ id: '42' }).title, the proxy records the exact selection path and schedules a single batched HTTP request on the next microtask.
Initializing the Client
import { createClient } from 'gqless';
import { generatedSchema, scalarsEnumsHash } from './schema.generated';
export const client = createClient({
schema: generatedSchema,
scalarsEnumsHash,
queryFetcher: async (query, variables) => {
const res = await fetch('https://api.example.com/graphql', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query, variables }),
});
return res.json();
},
});
Core Execution Flow
- Selection capture: Property reads traverse ES6 JavaScript Proxy traps to assemble an AST selection tree.
- Deduplication & batching: Multiple sibling components reading different fields on the same root query collapse into one GraphQL document.
- Normalized merge: Returned entities with matching
id/__typenamekeys update shared cache entries across the app.
Explore all client tuning flags in ClientOptions, learn how to warm routes with prefetch, or read the full ES6 Proxy query generation architecture guide.