Graphitron’s multi-tenant model is database-per-tenant: every tenant-scoped table carries a tenant column, each tenant’s rows live in that tenant’s own database, and the generator routes every statement to the right database from what the operation itself says. This page is the wiring recipe; the classification rules (which fields route how, and which schemas are rejected as unroutable) are enforced at build time.

1. Name the tenant column

Point the plugin at the column that scopes your tables:

<configuration>
    <tenantColumn>organization_id</tenantColumn>
</configuration>

Tables carrying the column are tenant-scoped; tables without it are global reference data, read and written on the connection your source picks for a key with no tenant (see §2). The tenant key’s Java type is read off the catalog, and it types every tenant-keyed runtime surface, so wiring a map keyed with the wrong type is a compile error. All tables carrying the column must agree on its Java type and on the Java type of the database value behind it, so a column a converter maps to String on one table cannot be a plain varchar on another. Graphitron compares keys through the converter of the first table carrying the column, so map the column through one converter everywhere: two different converters between the same types cannot be told apart at build time, and the first table’s then decides for both.

Tenant keys are compared by the value the column stores. When a converter maps the column, graphitron puts every key through it and back before comparing: with an INTEGER column mapped to String, a client sending "0194" reaches the same tenant as one sending "194", exactly as the SQL does. The keys you supply get the same treatment. Name your source’s tenants in whichever spelling you have, and graphitron reduces them to the column’s form before it fans out; the connection key your source receives reports that form, so key your pools by it. To key your own state the same way, call OwnedConnections.canonicalTenantKey.

A tenant value the column cannot store, such as "abc" on a numeric column, is a client error. So is a number outside the column’s range or precision: "4294967297" on an INTEGER column is refused, not wrapped onto another tenant. So is a value too large to read, by the bound on a value’s size that federation keys share. A value the column stores by coercion names the tenant the query itself reads: on an integer column "1.5" is bound as 1 in the SQL, so it reaches tenant 1, and only if the request may read tenant 1.

2. Choose each tenant’s connection in your source

The runtime holds no pools. Each request’s connections come from the ConnectionSource you pass with it, and in a tenant build the ConnectionKey it receives carries the tenant: key.tenant() is an Optional of your tenant key type, the routed tenant, or Optional.empty() for the connection every read and write of a global table runs on. Choose the pool from it, and name the tenants this request may span:

Map<Integer, DataSource> byTenant = Map.of(
    1, tenantOnePool,
    2, tenantTwoPool);
var runtime = Graphitron.runtime(SQLDialect.POSTGRES);              // once, at wiring time
var graphql = runtime.newGraphQL(Graphitron.buildSchema(b -> {})).build();

Set<Integer> permitted = permittedInstitutions(jwt);   // from the caller's claims, narrowed to this deployment
var source = ConnectionSources.mounting(
    key -> key.tenant().map(byTenant::get).orElse(defaultPool),
    permitted,
    (connection, key) -> Routines.connect(DSL.using(connection, SQLDialect.POSTGRES).configuration(),
        key.tenant().orElse(null), claims),
    (connection, key, handle) -> Routines.disconnect(DSL.using(connection, SQLDialect.POSTGRES).configuration(), handle));

In a tenant build ConnectionSource names its tenants, tenants(), the tenants this request may span, so a source without them does not compile: ConnectionSources.of and ConnectionSources.mounting take them after the pool, and a source of your own is built with ConnectionSource.of(acquire, tenants). The factories are the same as in any other build:

ExecutionInput input = Graphitron.newOwnedExecutionInput(source)
    .query(query).build();

Which tenants a request may reach is your source’s to say. Refuse a tenant by throwing KeyNotPermitted from acquire: the field that asked, whether its tenant was named by an argument, decoded from a node-id argument or handed down from a parent, answers with a client error carrying the refusal’s message, and the rest of the request runs. The lookups node, nodes and _entities instead answer an id whose tenant your source refuses with null, exactly as they answer an id that does not exist, and resolve the rest of the batch normally; a client cannot tell the two apart, by design. Graphitron remembers a refusal for the rest of the request, so your source is asked once per tenant however many fields name it. A tenant you refuse should not be asked of a pool first, so refuse before you look one up and a caller cannot tell a tenant you host from one you do not. An id whose tenant slot does not decode as a value of the tenant column is malformed and answers null on the lookups the same way, without opening a connection; on an argument it gets the malformed-id client error, since the slot is part of the id. Any other throw from acquire fails the request as a whole (see the end of §3). Your source’s tenants() is the domain of @tenantFanOut fields (see §3).

Connections are taken lazily, one per distinct tenant the operation actually touches, and your mount runs on each, so sessions, row-level security, and transaction boundaries behave exactly as in single-tenant operation, per tenant. A $session-bound service parameter likewise receives the handle of the tenant connection its call runs on, never a neighbor’s. Tenant keys that share one DataSource still get one connection and one mount each, each with its own key. The unmount receives the key as the mount did.

Every read and write of a global table runs on the key with no tenant, so on the pool your source picks for it, whatever tenant the request otherwise reaches: root fields over global tables, @splitQuery fields over global tables (also below a tenant row), node, nodes and _entities for global types, writes to global tables, and @service fields that are handed no connection, return no tenant-scoped table’s rows, and name no tenant or name one only through values that may all be left out. If your global tables are present in every tenant database, your source may serve that key from one of them; there is no other way to name a tenant for global reads.

Routing is divined from the operation: a non-null argument bound to the tenant column routes the statement and hands the tenant down its subtree; global tables read the key with no tenant (above). A tenant-scoped field that nothing routes is a build error, never a silent read of the wrong database.

The same holds for a field whose tenant comes only from optional arguments: a request that leaves them all out names no tenant, so the build rejects the field. Mark the field @tenantFanOut (§3) to query every tenant the request may see when none is given, or make one of the arguments non-null. An argument counts as non-null only when every step of its path is: the argument itself, each input field down to the one naming the tenant, and the elements of any list on the way, since [ID]! can arrive as [null].

A non-null list can still arrive empty, and an empty list names no tenant. When a field’s tenant comes only from list elements, graphitron answers an empty list without opening any tenant connection where the answer is plainly empty: a bulk mutation writes nothing and returns an empty list (an empty data list and no errors, under a payload), a @lookupKey query returns an empty list, and a @service whose answer is a list returns an empty list without calling the service. A service that must run even for an empty batch, to write an audit row say, needs a tenant from outside the list: a non-null argument or a context argument. Where graphitron cannot build the answer itself (a service returning its own payload class, a filter where an empty list means "no filter", or a tenant read from a list nested inside each element, where the outer list may still hold rows), the request fails with an error naming the field and the empty argument.

A reference from a global table into tenant data can route on the parent row. When the foreign key a field follows lands on the tenant column, the parent row’s value at the paired column names the tenant that holds the child row, so each parent row’s child is fetched from that tenant’s database. Such a field is a query of its own, whether or not you write it split; for now write it @splitQuery, which the build asks for (TENANT_FAN_OUT_INLINE_UNSUPPORTED) until it generates the field as a query of its own without it. Parents naming the same tenant share one batched statement. A parent with no value at that column has no child. Like any routed tenant, your source may refuse it, and that child then fails with a client error. The parent row decides even when the parent was reached under another tenant, because a tenant’s database holds only rows carrying that tenant: a registry row pointing at institution X has its child in X’s database, whichever tenant the request arrived through.

A @service field cannot route that way yet. One below a global table that reaches a tenant’s rows, by a key landing on the tenant column or by one naming no tenant, is refused at build time (SERVICE_TENANT_FAN_OUT_UNSUPPORTED), since its parents would be grouped by the tenant each names, which is not generated for a service yet. Read such rows with a field graphitron fetches, or put the service under a type whose rows a tenant holds.

Fields of a type without @table, reached through a field on a @table type, route exactly as they would on that @table type, including the parent-row routing just described.

A field under a global table’s rows that reads a tenant’s rows by a key that does not land on the tenant column has no tenant to run on: the parent row names none, and nothing is handed down from a global row. The build refuses it (UNROUTED_CHILD), whether a @service answers it or graphitron reads it. Follow a key landing on the tenant column, or read the rows from a field under a tenant’s rows.

Below a field that already has a tenant, either handed down or named by its parent row, a child field runs on that tenant even when its own arguments name the tenant column. There the argument only filters, inside the parent’s tenant database, so it can be optional, and a value naming another tenant cannot route the field elsewhere.

A @service field routes the same way. When its arguments carry the tenant, through a jOOQ record parameter binding the tenant column or a decoded @nodeId whose key holds it (a bean member typed as the node table’s record, a record parameter, or a top-level argument), the service method runs on that tenant’s connection and the tenant is handed down to the rows it returns, so tenant-scoped fields under a payload wrapper resolve. Every tenant-bearing id in the arguments must name the same tenant: an omitted optional id is skipped, and a batch naming two tenants is refused before the service is called. An empty batch that names no tenant does not call the service at all; see above. A @nodeId naming a multi-table interface or union cannot route the call, since its members decode the same id with their own key columns, so the build refuses a root service that needs a tenant and reads one off such an id, whatever else names it; name one node type instead. A service that takes a DSLContext or $session, as a parameter or through its class’s constructor, runs on its parent’s tenant when the parent is tenant-bound. A service returning a @table type over a global table runs on the key with no tenant whatever its arguments name, because graphitron re-reads the returned rows there. A root service whose tenant comes only from values that may all be left out runs on the key with no tenant when it needs none, being handed no connection and returning no tenant-scoped table’s rows; one that needs a tenant is refused (TENANT_SLOTS_OPTIONAL_ONLY) until one of those values is made required.

A service’s own SQL is opaque to graphitron, so a root service that is handed a DSLContext or $session must name its tenant in its arguments, or the build refuses it rather than run it on the key with no tenant. Take the node table’s jOOQ record with @nodeId(typeName:) instead of the encoded id as a String, and the call routes on the id. When no row exists yet and the tenant arrives as a plain value, as in a mutation that creates something at an institution, mark the argument or input field holding it with @tenant:

input CreateStudentInput { institution: String! @tenant  name: String! }

Or name it in the service’s argMapping, argMapping: "input: input, $tenant: input.institution", which says the same and is the preferred form, @tenant being due for removal; see @service. The call then routes on that value, which must have your tenant key’s Java type. Like any routed value your source may refuse it, and every value in one call, across a batch and beside any tenant-bearing ids, must name the same tenant. The marker is your statement that the service uses the value as its tenant, which graphitron cannot see. Graphitron has no global-data marker, and a service that needs a connection runs on its tenant’s (Alf, 2026-11-19): a root service handed a connection or the session handle names its tenant, and one that works only on global tables takes no connection. The reverse holds too: a service that takes a tenant’s record runs on that tenant’s database, so it should not take one if it only works on global tables.

A node id (and a federation representation) carries its tenant inside the key, and what happens next turns on where it arrives. At a dispatch surface (node, nodes, _entities) the batch partitions per decoded tenant, one statement per tenant. Fields below a node or entity that dispatch resolved read from that node’s tenant, so a nodes batch spanning tenants keeps each node’s subtree on its own database. Anywhere else, a write keyed by ids or a filter reading them, the call is one statement on one connection, so every id in it must decode to the same tenant; a call mixing tenants is refused before any SQL runs, naming the disagreement. This includes a reference id on an update input. An update that repoints a row at a parent in the same table, where the parent’s key carries the tenant, is fine as long as the parent lives in the row’s own tenant; if it does not, the call is refused the same way. An update never moves a row between tenants, so an input field that writes the tenant column itself is a build error. The asymmetry is the one between reads and writes: a read can be split across databases, and a write cannot.

A filter is the one exception, when the same filter also takes a required tenant value that it compares against the table’s own tenant column. That value decides the tenant, and the ids only filter inside it: an id naming another tenant matches no row, as an id that exists nowhere would, and the field answers without an error. With

input FilmActorFilter {
    filmId: Int! @field(name: "film_id")   # the tenant column
    actors: [ID!] @nodeId(typeName: "FilmActor")
}

filmActors(filter: { filmId: 1, actors: […​] }) reads tenant 1 and returns only the listed actors that belong to it. The exception covers ids the client may leave out, compared by the predicate Graphitron writes. An id whose predicate your own @condition takes over still has to agree with the tenant value, because Graphitron cannot see what your condition compares, and so do the ids of a write.

A federation key that cannot carry the tenant column, such as a username unique only within one institution, names no tenant to route on, and such an entity type is a build error: a request names no tenant to fetch it from. Add the tenant column to the key, or mark that key resolvable: false. (The @defaultTenant directive that once resolved such keys on a tenant the request named is no longer supported; see @defaultTenant.)

3. Fan a field out across tenants

When no single tenant is named ("all results for this student", wherever they live), mark the field with @tenantFanOut: the query runs once per tenant the request may see, in parallel, and the results come back as one list.

A fanned field can take optional arguments that name the tenant, such as a filter on student ids whose keys carry the institution. When the request gives one, only the tenants its values name are queried; when it gives none, the field fans out over every tenant the request may see. Either way the rows answered are the same ones, because a tenant’s database holds only rows naming that tenant: narrowing saves the connections to tenants that cannot answer.

The tenants a fanned field runs over are your source’s tenants() (§2), in the order it gives them, each in the tenant column’s form, derived from your request’s claims and any other request-level policy (operational exclusions, residency, product rules). Graphitron reads them once per request, on the first fan-out. A tenant the request may not see is simply not named. Each tenant named is asked of your source, which may still refuse it with KeyNotPermitted; that tenant then contributes a failed element, as any failing tenant does.

If your claims can name tenants this deployment does not serve, leave them out of tenants(); that is your explicit statement, not a silent runtime drop.

Tuning fan-out

Fan-out parallelism is bounded and configurable on the generated runtime: a concurrency cap (default 8 scatter workers in flight, one bounded pool shared by all of the runtime’s requests) and a per-field deadline (default 10 seconds), set as plain constructor values. Supply your own Executor instead if you want to own threading (for example virtual threads); the deadline still applies.

// Explicit cap and deadline over the runtime-owned bounded pool:
new GraphitronRuntime(SQLDialect.POSTGRES, settings, 16, Duration.ofSeconds(5));
// Or bring your own executor; you own the concurrency bound, the deadline stays enforced:
new GraphitronRuntime(SQLDialect.POSTGRES, settings, myExecutor, Duration.ofSeconds(5));

A tenant that fails or misses the deadline contributes one null element and a path-bearing entry in the response’s errors array; the field’s element nullability chooses whether that stays partial data ([Thing]) or nulls the whole field ([Thing!]). See the directive reference.

The one exception is a failed acquisition. When your source throws anything but KeyNotPermitted on any tenant (a mount the database rejects, say), the request fails as a whole instead of returning partial data: GraphQL.execute throws AcquisitionFailedException, one arm of the request rejection, as described in A request rejection rejects the request. The first failure answers every later acquisition in the operation. On a mutation, the top-level field during which an acquisition fails fails and rolls back on every tenant it touched, but an earlier top-level field has already committed by then, and the rejection does not undo it (Transactions on the owned-connection path).