ProjectionsSchemaField
@from
The @from directive can be used to calculate the value of a field from an expression.
| Argument | Description |
|---|---|
| events | restrict the usage of the directive to a list of event types |
| topics | restrict the usage of the directive to a list of topics |
| condition | restrict the usage of the directive to the match of a condition expression |
| value | calculate the value of the field by using an expression |
Example
Let's say you have the following schema:
type User @upsertOn(...) {
email: String! @from(
events: ["createUser", "updateUser"]
topics: ["userManagement"]
condition: "payload.name != nil"
value: "payload.name + '@becklyn.com'"
)
}This schema will generate the email field for all events of the topic userManagement that have the types createUser or updateUser and have a payload field name which is not nil.
The value will be the value of the payload field name combined with the string @becklyn.com.
For this event Payload:
{
"name": "John"
}The value of the projection entry field email will be "John@becklyn.com".