Marks a table-bound entity in a federated subgraph that owns the data another subgraph vouches for. Graphitron gives the type a voucher field, internalGraphitronVoucher: String, which the router fills with the voucher it fetched from the issuing subgraph’s @issue type; Graphitron verifies it and reads the vouched row on the connection your connection source leases for a key carrying the voucher’s vouched-for values, so your database’s row-level security decides what the vouched-for values unlock. The voucher is not a column and is never selected.
The entity and every field below it are read on that connection. A field its SELECT reads, reference children nested in it included, is read in the entity’s own statement; a field that runs a query of its own, a split query, a routine, a polymorphic field or a @service, runs on the connection key the entity row hands down, and so does everything below it. A type with a connection below it, at any depth, whether the connection is an @asConnection field, a field returning a connection type or a @service returning one, is refused for now with VOUCHER_ACCEPT_NOT_GENERATED, since a connection’s count and facets do not yet read on the vouched connection. The same field reached from outside a vouched entity’s subtree runs on the request’s own connection.
SDL signature
directive @accept(scope: String!, key: String, vouchesFor: String!) on OBJECT
| Parameter | Type | Meaning |
|---|---|---|
|
|
What the voucher is for. Names the scope of the issuing subgraph’s |
|
|
The field set of the authored |
|
|
The fields of this type the voucher’s vouched-for values parse into, a field set as |
Canonical example
type VgsResultat @table(name: "vgs_resultat") @key(fields: "id")
@accept(scope: "vgs-resultater", vouchesFor: "eierId") {
id: ID!
eierId: String! @inaccessible
fag: String!
karakter: Int!
}
The voucher decodes to id, the type’s one authored key, which its lookup part supplies since vouchesFor does not name it, and its vouched-for values parse into eierId. Name and type both exactly as the issuing subgraph’s absorbed fields. Vouching for the key itself, vouchesFor: "id", leaves the lookup part empty: the key’s value is then the vouched-for one, and it both finds the row and decides access.
How a voucher is read
For each _entities representation carrying the voucher, before any type is resolved:
-
The voucher is decoded and checked: its format, its signature over the token and the representation’s
__typenameagainst your verification keys, its expiry (with 30 seconds of tolerance for clock skew), its scope, and that its vouched-for section names exactly this type’svouchesForfields and its lookup section exactly the fields of the key it decodes to thatvouchesFordoes not name. Each key field is supplied by one section, so no value arrives twice. A voucher longer thanVoucherCodec.MAX_TOKENcharacters (16384), or carrying a number whose text is longer thanVoucherCodec.MAX_NUMBER_TEXT, is malformed before it is decoded, and no value in it is read until its signature verifies, so a forged token costs work in proportion to its bounded length. A representation that carries the voucher is always read through it, never past it by plain key fields. -
Each value is coerced to its field’s column once, as a plain representation’s key values are; a value no column takes is a failed check, not a missing row.
-
The vouched-for values are admitted into the request’s set: a
ConnectionKey.VouchedForrow with a component per vouched-for field, typed by its column (VouchedFor::eierIdin the example). The first distinct values in representation order are admitted, up to the cap. -
Once every representation of the
_entitiesfield has been checked, the key’s values, each from the section that supplies it, are read through the authored key’s own SELECT on the one connection your source leases for the request’s vouched key, the generatedConnectionKeywhosevouchedFor()is the whole admitted set.
Your ConnectionSource reads the set off the key and returns a connection whose session sets it where your policies read it, so a policy tests a row’s membership in the set; for the key whose set is empty it returns the request’s own connection. A build that accepts vouchers has no escape hatch: Graphitron.newExecutionInput(dsl, …) is not generated, since a vouched connection can only come from the request’s source.
The voucher is verified with the generated VoucherKeys, the last argument of every Graphitron.runtime(…) overload: VoucherKeys.accepting(Map.of(keyId, publicKey)) holds the issuing subgraph’s Ed25519 public keys by the key id each voucher carries, so a key is rotated by adding the new id beside the old one. How-to: Voucher handover makes the keys, wires both subgraphs and writes the connection source and policies.
A voucher that fails any check rejects the request as a whole, before any connection is taken: GraphQL.execute throws the generated VoucherRejectedException in place of a result, its message naming the check that failed and nothing from the token. It is an arm of the generated RequestRejectedException, which the facade’s Graphitron.requestRejection(thrown) answers; see A request rejection rejects the request. A request admits at most a thousand distinct vouched-for values, or what the runtime’s VouchedValueLimit answers (Graphitron.runtime(…).withVouchedValueLimit(env → limit), asked once per request; an answer below 1 admits none): a representation whose value is past the cap answers null with an error at its own index that names the limit and no value, and takes no connection, while the rest resolve. The cap never rejects the request, so it is not mistaken for a denial. A second _entities field in the same operation reads on the same connection: a value the first field admitted resolves, and any other fails as past the cap. A plain representation of the type’s authored key resolves on the request’s own connection, under the caller’s own access: a voucher only ever adds access. A representation whose voucher is null carries none: its slot is null, as a key value that is null matches no row, no connection is taken for it, and it never rejects the request.
Every redemption and rejection is logged at INFO on the logger no.sikt.graphitron.voucher.audit, by vouch id, scope and outcome (redeemed, rejected with the check that failed, or not admitted because of the cap, LIMIT); never the token, its values or the connection key.
What the subgraph publishes
-
@key(fields: "internalGraphitronVoucher")on the accepting type, resolvable, after every key you wrote, so a router hands this subgraph the voucher it fetched from the issuing one. Your own keys are untouched, so the type still resolves by them under the caller’s own access. -
The voucher field,
internalGraphitronVoucher: String, marked@inaccessibleso clients never see it. You do not write it; its name is the same in every subgraph, so the issuing and accepting sides cannot disagree on it. It is nullable here, as on the issuing side, which gives no voucher to a row whose values it cannot sign: this subgraph receives a voucher in a representation but never computes one, so a row it reads by any other route has none to give. The link imports@inaccessiblefor you.
Constraints
Each refusal below is reported at the @accept.
| Code | Rule |
|---|---|
|
The schema has a federation |
|
The type declares no field named |
|
The type is not also marked |
|
The build configures no |
|
|
|
Each vouched-for field names a field of the type: not a name the type does not declare, not |
|
No vouched-for field is named twice. |
|
Each vouched-for field reads one column of the type’s own table, as a key field does: not a list, not a field read some other way. |
|
The type has an authored |
|
|
|
|
|
|
|
Every |
|
No connection below the type, at any depth through the types its subtree reads: a connection does not yet read on the vouched connection. Read those rows as a list instead, in the entity’s SELECT, a split query or a |