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

scope

String!

What the voucher is for. Names the scope of the issuing subgraph’s @issue(scope:).

key

String

The field set of the authored @key the voucher decodes to, as @key(fields:) spells it. Leave it out when the type has exactly one authored resolvable key.

vouchesFor

String!

The fields of this type the voucher’s vouched-for values parse into, a field set as @key(fields:) spells one: whose rows are vouched for. Names the same fields as the issuing subgraph’s @issue(vouchesFor:). A vouched-for field may be a field of the key the voucher decodes to, and then it is supplied by the vouched-for section; the key’s other fields are supplied by the lookup section. A vouched-for field may be @inaccessible, so the owner is not published to clients.

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:

  1. The voucher is decoded and checked: its format, its signature over the token and the representation’s __typename against 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’s vouchesFor fields and its lookup section exactly the fields of the key it decodes to that vouchesFor does not name. Each key field is supplied by one section, so no value arrives twice. A voucher longer than VoucherCodec.MAX_TOKEN characters (16384), or carrying a number whose text is longer than VoucherCodec.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.

  2. 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.

  3. The vouched-for values are admitted into the request’s set: a ConnectionKey.VouchedFor row with a component per vouched-for field, typed by its column (VouchedFor::eierId in the example). The first distinct values in representation order are admitted, up to the cap.

  4. Once every representation of the _entities field 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 generated ConnectionKey whose vouchedFor() 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 @inaccessible so 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 @inaccessible for you.

Constraints

Each refusal below is reported at the @accept.

Code Rule

VOUCHER_WITHOUT_FEDERATION_LINK

The schema has a federation @link: a voucher only makes sense where a router plans across subgraphs, and the key it is reached by needs the link.

VOUCHER_FIELD_NAME_TAKEN

The type declares no field named internalGraphitronVoucher, the name Graphitron mints the voucher field under. Such a field is refused, not taken for the voucher, and no voucher field is minted beside it.

VOUCHER_MARKERS_BOTH

The type is not also marked @issue: a type issues or accepts one voucher. Refused at each marker.

VOUCHER_ACCEPT_WITH_TENANT_COLUMN

The build configures no <tenantColumn>. A vouched connection is keyed by the vouched-for values alone, and a voucher is not yet paired with the tenant of the key it decodes to.

VOUCHER_VOUCHES_FOR_EMPTY

vouchesFor selects at least one field.

VOUCHER_VOUCHED_FOR_NOT_A_FIELD

Each vouched-for field names a field of the type: not a name the type does not declare, not internalGraphitronVoucher, not a nested selection.

VOUCHER_VOUCHED_FOR_REPEATED

No vouched-for field is named twice.

VOUCHER_VOUCHED_FOR_NOT_A_COLUMN

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.

VOUCHER_ACCEPT_WITHOUT_KEY

The type has an authored @key this subgraph resolves it by, which the voucher decodes to.

VOUCHER_ACCEPT_KEY_AMBIGUOUS

key is given when the type has more than one authored resolvable key.

VOUCHER_ACCEPT_KEY_NESTED

key has no nested selection: the lookup part carries top-level scalar fields.

VOUCHER_ACCEPT_KEY_UNKNOWN

key names the fields of an authored resolvable key of the type, in any order.

VOUCHER_ACCEPT_VOUCHED_FOR_DIFFERS

Every @accept in the graph vouches for values of one shape, the same vouched-for field names each reading a column of the same Java type, since the graph’s vouched connections are keyed by one generated ConnectionKey. Refused at each @accept whose shape differs from the first accepting type’s by name.

VOUCHER_ACCEPT_NOT_GENERATED

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 @service.