reym
Projections/Schema/Field

@fromJwtData

A JWT can contain a field called data. This field can contain a key-value object. The @fromJwtData directive uses this object to fill the value of the field that uses the directive with a value from the JWT data object. The value that is used to fill the field is identified by the key argument of the directive.

The value of the field will be overridden by the JWT value. So that even if the event would set the value of that field, the directive will override it.

Example with Single Data

If you have this schema:

user.graphql
type User @upsertOn(...) {
    tenant: ID! @fromJwtData(key: "tenant-id")
}

then this JWT:

jwt.json
{
    // ...
    "data": {
        "tenant-id": "example-id",
    },
    // ...
}

will fill the projection entry field tenant with the value "example-id".

Example with Array Data

If you have this schema:

user.graphql
type User @upsertOn(...) {
    tenant: ID! @fromJwtData(key: "tenant-id")
}

then this JWT:

jwt.json
{
    // ...
    "data": {
        "tenant-id": ["example-id", "other-id"],
    },
    // ...
}

will fill the projection entry field tenant with the value "example-id" as that value is the first value of the array in the JWT data field tenant-id.

Example with Empty Data

user.graphql
type User @upsertOn(...) {
    tenant: ID! @filterFromJwtData(key: "tenant-id")
}

In contrast to the examples above a JWT like this (where the tenant-id data is not defined):

jwt.json
{
    // ...
    "data": {},
    // ...
}

will leave the projection entry field tenant empty / unchanged.