Skip to Content
Athanor

Wiring: layers and the runtime

The graph reconciles its own requirements once, off the request path; request-scoped services come per execute; there is no codegen.

Nodes and mutations both declare requirements, and both are in the manifest — so the graph reconciles its own dependencies once, off the request path:

// server/layers/graph.ts
export const GraphLive = Layer.mergeAll(Database, ClientService, …) satisfies Layer.Layer<
  Exclude<GraphRequirements | FieldsRequirements<typeof Query.fields>, RequestScoped>,
  unknown,
  never
>;

// server/athanor/runtime.ts
const runtime = ManagedRuntime.make(GraphLive, { memoMap });
export const runGraph = (effect) => runtime.runPromise(effect);

GraphRequirements comes from the generated manifest as NodeRequirements<typeof Nodes> | MutationRequirements<typeof Mutations> — unioned by the compiler, not by a build step, and NodeRequirements includes what a node's fields need, not only its load. Add FieldsRequirements<typeof Query.fields> for the root's own fields and the check is complete: a service the app forgot is a build error naming it, not a failed request.

Request-scoped services (the viewer, the request cache) are Excluded here and come from build({ request }) instead — a thunk called once per execute, so a cookie-derived viewer can never be memoized for the life of the process. Their own requirements ride outward to the runtime above, which is how a per-request viewer still resolves against one process-wide JWKS cache.

There is no runQuery and no per-call provide: execute uses the configured runtime, so a page is Athanor.execute(Query, args) and nothing else.

RequestCache is a requirement, not a config default. It is what makes independently rendered Server Components share loaders — <Card id={a}/> and <Card id={b}/> run their own execute and never share a fiber tree. Its type is on build({ request }), so forgetting it is a compile error; an earlier version defaulted it to React.cache, which is a no-op outside a React request and degraded silently to N+1.

No codegen

There is none. The one thing it used to emit — a typed tuple of every node, because TypeScript cannot accumulate types through side-effecting registration — is now the types list you hand build, and build refuses a declared node that is not listed, so the list cannot fall behind the declarations. The graph-wide checks (a plain field declared with a node's schema) run in build too, at the one moment every declaration exists.

Requirements derive from the same value:

export const graph = { Query, Mutation, types: [ClientNode, VaultNode, …] } as const;
export type GraphRequirements = GraphRequirementsOf<typeof graph>;

Subscription handles — the client-safe { name } with the frame type — are one line each, with the name checked against the root:

import type { Subscription } from "@/server/athanor/schema"; // type-only: erased
export const OrderLive = handle<typeof Subscription>()("orderUpdates");

On this page