Objects, fields and the Query root
An object is fields with no identity and derives from its parent. Seven field kinds, field arguments, nullable edges and null propagation.
An object is fields with no identity — a Viewer, an aggregate. It derives from its parent.
Mounted on Query with f.object, its parent is the context, and that is where a request becomes
graph data:
// server/athanor/schema.ts
export const Viewer = Athanor.Object(ViewerSchema, {
resolve: (ctx: Ctx) => ({
_tag: "Viewer" as const,
actorGlobalId: actorGlobalId(ctx.viewer.actor),
organizationId: orgIdOf(ctx.viewer.actor), // may be null
}),
fields: (f) => ({
actor: f.union(ActorNodes, (view) => view.actorGlobalId),
organization: f.node(OrganizationNode, (view) => view.organizationId), // nullable edge
vaults: f.collection(VaultNode, { ids: () => VaultService.use((v) => v.listIds) }),
notifications: f.collection(NotificationNode, { ids: () => /* the viewer's own */ }),
}),
});
export const Query = Athanor.Query((f) => ({
viewer: f.object(Viewer),
admin: f.object(AdminObject), // not the viewer's: searches across orgs
clients: f.connection(ClientConnection, …), // org-wide, paginated, with args
}));Field kinds:
| kind | for | caches? |
|---|---|---|
f.object | another object, derived from this parent — the selector chains through it | never |
f.node | traverse to one node by key; a K | null key makes it a nullable edge | via that node |
f.collection | keyed, unpaginated — a reference table | membership only |
f.connection | Relay pagination — ordered ids + cursors; args adds a filter or sort beside the spec's four | spine only |
f.union | dispatch a global id to one of several nodes | via those nodes |
f.field / f.list | computed values with no identity; f.field may take args | never |
f.collection and f.connection yield keys. Entities come from each node's own cached load —
that is the normalization. A missing or denied key is dropped rather than fatal, so a spine naming
a row you can no longer see degrades gracefully.
f.listdeclared with a registered node's schema is a build error. Those rows would bypass the entity cache, its per-id invalidation and the batch loader. Usef.collection.
Objects are synchronous; their fields are not
resolve on an object is a plain function: it derives a handle from its parent and cannot reach
a service. That is deliberate (anything that loads is a node, and a node has a gate), and it is
not a limitation — an object that needs async data puts it in its fields, each of which is an
Effect. Organization loads { id, name } in one batched request; businessProfile, wireAccount
and custodianIntegrations are fields that each hit their own service, lazily, when selected. That is
GraphQL's model too: an object type is a namespace whose resolvers run per field.
The same holds for chaining: app.viewer.organization.businessProfile reads through two hops and
the chain is Effect all the way down, so where the work happens makes no difference to the caller.
Fields with arguments
users: f.field(Schema.Array(AdminUserSearchResult), {
args: Schema.Struct({ query: Schema.String }),
resolve: (_admin, { query }) => AuthClient.use((auth) => auth.admin.searchUsers({ query })),
}),
// at the selector:
query((app, variables) => ({ users: app.admin.users({ query: variables.q }) }), …)That is a GraphQL field argument. The args schema is what an adapter decodes a wire value with.
Nullable edges and null propagation
f.node(Node, (parent) => parent.key) where the key may be null is a nullable edge: the
field is null rather than a failure, and — because the selector chains through node fields — a
null propagates down anything read through it, exactly as GraphQL's does:
query((app) => ({ name: app.viewer.organization.name })); // string | nullA caller with no organization reads null; nothing throws, nothing guards by hand.
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.
Fragments and views
A fragment is a declared field slice whose return type is the mask. A view is a fragment that renders itself; match is the inline fragment per union variant.