The builder, then the graph
Two phases, because declarations reference each other in both directions: declare against a builder, build the graph once from the roots.
Two phases, because declarations reference each other in both directions: a node's fields name
other nodes, Query names objects, mutations record writes against nodes. So you declare
against a builder, and build the graph once, from the roots.
// server/athanor/alembic.ts — the builder, and nothing else
import { define } from "@athanor/alembic/define";
export type Ctx = { readonly viewer: Policy.ViewerService };
export const Athanor = define<Ctx>();
export const { mutation, subscription } = Athanor;Every node, object, mutation and subscription file imports Athanor from here. Keep this module
free of anything request-shaped: tests import every declaration in plain bun.
// server/athanor/schema.ts — the roots, then the graph
export const Query = Athanor.Query((f) => ({
viewer: f.object(ViewerObject),
clients: f.connection(ClientConnection, { page, count }), // org-wide, paginated, with args
}));
export const Mutation = Athanor.Mutation({ updateClient, createClient });
export const { query } = Athanor.build({
Query,
Mutation,
types: Nodes, // the generated manifest — see [No codegen](/alembic/wiring#no-codegen)
context: () => Effect.map(Policy.Viewer, (viewer) => ({ viewer })),
request: () => Layer.mergeAll(Viewer, RequestCache), // once per execute — see [Wiring](/alembic/wiring)
runtime: (effect) => import("./runtime").then((m) => m.runGraph(effect)),
cachedLoad: (typename, id) =>
import("./cached").then((m) => m.cachedLoad(typename, id)),
});
export { Athanor };That is GraphQL's schema, on purpose: three roots plus a set of types. After build the same
Athanor executes — Athanor.execute(Query, args), Athanor.mutate(updateClient, input).
Anything that executes imports Athanor from schema.ts (or a barrel over it), which is what
guarantees the graph was built before it is used.
Global ids
A global id is base64("Client:CLT_1") by default, and a node's default cache tag is the readable
half. Both are configurable, because the format is a persisted identifier — it is in URLs and in
whatever a client already stored:
build({ globalId: { encode, decode, tag } }); // GlobalIdCodecMint handles through Athanor.globalId.encode(...), never by importing the default, so a
configured codec is used everywhere or nowhere.
Alembic
The RSC data graph the product is built on: Relay's good ideas, colocated fragments, masking, batched loading, per-entity caching, without a GraphQL runtime.
Declare a node
A node is a record: identified, batched over one service, cached once per entity. Four things are load-bearing, and one row property makes tenant isolation possible.