@tenant marks the argument or input field of a root @service field that carries the tenant, in a build with database-per-tenant routing (<tenantColumn>). The service runs on that tenant’s connection, and the tenant-scoped fields under its result inherit it.
input CreateStudentInput {
institution: String! @tenant
name: String!
}
type Mutation {
createStudents(input: [CreateStudentInput!]!): CreateStudentsPayload
@service(service: {className: "...StudentService", method: "createStudents"})
}
SDL signature
directive @tenant on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
The directive carries no arguments. Put it on a scalar argument of the service field, or on a scalar field of an input object the service receives as a Java bean or record, at any depth and inside lists. It is the fix for a service that is handed a DSLContext or $session and has nothing else naming its tenant: a mutation that creates something has no row and no id yet, only the value that says where the row goes.
What the build checks
The marker is your statement that the service uses the value as its tenant, which graphitron cannot see, since the service’s own SQL is opaque. Everything around that statement is checked.
The value is read as the client sent it, so its GraphQL type must arrive as your tenant key’s Java type: String or ID for a String key, Int for an Integer key, a custom scalar whose Java type is the key type. Graphitron does not convert or normalise the value; one your connection source refuses fails the field with a client error. Every value in one call must name the same tenant, across the elements of a list and beside any id that carries a tenant, or the call is refused before the service runs.
Build-time rejections
The build rejects the marker where it decides nothing, naming each field that reaches it:
-
in a build without
<tenantColumn>, where nothing routes by a tenant (TENANT_ROUTES_NOTHING); -
on a root service whose result is a global
@tabletype, which runs on the default source whatever its arguments name (TENANT_ROUTES_NOTHING, the detail naming the table); -
anywhere the field it reaches is not a root
@service(TENANT_SITE_UNSUPPORTED, the code$tenantdraws written anywhere but a root@service’s `argMapping): a query field binds the tenant through@field(name:)on the tenant column, and a child service inherits its parent’s tenant; -
on a field of an input object the service takes as a jOOQ record (
TENANT_MARKER_ON_RECORD_MEMBER): the field bound to the tenant column with@field(name:)already names the call’s tenant from the record, so remove the marker; -
beside
@nodeId, since the id already carries its tenant (TENANT_MARKER_BESIDE_NODE_ID); -
on a field whose type is an input object, or a scalar not arriving as the tenant key’s type (
TENANT_VALUE_TYPE_DISAGREES).
$tenant says the same
The service’s argMapping names the same value with $tenant: <path>, which is the preferred form, this directive being due for removal;
see @service. Where both are written for one call they must name the
same value: a $tenant pair and a @tenant on another argument or input field are refused as
TENANT_NAMED_TWICE, since nothing says which tenant the call runs on. A value whose GraphQL type
does not arrive as the tenant key’s Java type is refused as TENANT_VALUE_TYPE_DISAGREES, whichever
way it is named. The other rejections above hold for a $tenant pair as they do for the marker: a pair
landing on a field of a jOOQ record is refused as TENANT_MARKER_ON_RECORD_MEMBER, and one where
nothing routes by a tenant as TENANT_ROUTES_NOTHING.
See How-to: Tenant scoping for the other ways a service names its tenant.