Queries
query binds a selector to the Query root and decodes its input at the boundary. Nesting is where the page's boundaries are; execute hands back each part on its own, never a promise for the whole.
query comes from build, bound to your Query root. build receives (app, variables) — the
root selector first, the decoded input second. The input decodes at the boundary, so a query's
input schema is also the page's searchParams schema.
export const ClientsSidebarQuery = query(
(app) => ({
viewer: { clients: app.viewer.clients(ClientRow) },
}),
Schema.Struct({}),
);
export const ClientDetailQuery = query(
(app, variables) => ({
header: client(app, variables.clientId).pipe(
fragment(ClientHeaderFragment),
),
info: client(app, variables.clientId).pipe(fragment(ClientInfoFragment)),
}),
Schema.Struct({ clientId: Schema.String }),
);app.viewer is an object field, so it chains: app.viewer.clients(…) selects through the
viewer, and app.viewer.pipe(fragment(F)) spreads onto it. app.node(id) and app.nodes(ids) are
on every Query selector without being declared, typed over types.
Reading the same entity from several keys collapses to one batched load — that is what
RequestCache is for.
Put the query beside the render root that runs it, not beside the component that reads the result. Fragments and views colocate with components; queries colocate with roots.
Nesting is where the page's boundaries are
A plain object literal groups; an Effect resolves. Nesting is not a hop in the graph and
costs no extra read — it says which parts of the page settle on their own.
query((app) => ({
viewer: {
account: app.viewer.account,
Clients: app.viewer.clients(ClientRow),
},
custodians: app.custodians(CustodianChip),
}));
// → { viewer: { account: Promise, Clients: Component }, custodians: Promise }viewer is a plain object, because nothing loads it. So viewer.clients suspends in its own
boundary while viewer.account renders beside it.
The execution model
execute returns the selection with its leaves replaced — immediately, without awaiting: a
view leaf by a component that suspends on it, any other leaf by a promise of its value. There is
deliberately no promise for "the whole query": awaiting one would put the page behind its slowest
leaf, which is the thing this exists to avoid.
const { viewer, orders } = Athanor.execute(PageQuery, params);
return (
<>
<Header data={viewer.account} />
<Suspense fallback={<Rows />}>
<Clients data={viewer.clients} />
</Suspense>
<Suspense fallback={<Rows />}>
<Orders data={orders} />
</Suspense>
</>
);Every leaf starts on its own fiber under one scope, one context resolution and one loader map, so streaming costs nothing: sibling leaves still share a batch tick exactly as if they had been merged. Only the reporting is per leaf.
Invalid input throws at the call, before any resolver runs — not later on whichever leaf happened to be read first.
When a caller genuinely has nothing to do until everything is in — a route handler, a test — use
collect, which awaits every leaf and keeps the shape:
const { viewer, custodians } = await collect(
Athanor.execute(PageQuery, params),
);Leaves receive results, never fragments. Relay hands a component an opaque fragment ref and
the component reads its slice from a client store. There is no client store here — the server is
the store — so a fragment cannot travel: it is an Effect requiring Parent<E> and
ExecutionScope, and handing one to a client component would drag the graph into the bundle.
One execution per component is the other shape — the <Card id={id}/> pattern. Each card runs
its own execute; RequestCache is what collapses them into a single byIds:
{
ids.map((id) => (
<Suspense key={id}>
<Card id={id} />
</Suspense>
));
}Use nesting when the pieces belong to one screen and one fetch. Use per-component executions for lists, where each row is independently addressable — and note it only batches because the request cache is shared; that is the whole reason it is a service and not a default.
The entity cache
One use cache function for the whole graph, keyed by typename and id, with a bucketed clock so a cached read is deterministic.
Mutations
An ordinary Effect function with a declared input and a payload, registered under its name, recording the writes it made so the cache tags derive from the graph.