Skip to Content
Athanor

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:

kindforcaches?
f.objectanother object, derived from this parent — the selector chains through itnever
f.nodetraverse to one node by key; a K | null key makes it a nullable edgevia that node
f.collectionkeyed, unpaginated — a reference tablemembership only
f.connectionRelay pagination — ordered ids + cursors; args adds a filter or sort beside the spec's fourspine only
f.uniondispatch a global id to one of several nodesvia those nodes
f.field / f.listcomputed values with no identity; f.field may take argsnever

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.list declared 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. Use f.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 | null

A caller with no organization reads null; nothing throws, nothing guards by hand.

On this page