reym
Projections/Schema/Object

@removeOn

A projection definition can have zero, one or multiple @removeOn type directives.

Example

In the following case the removeUser event will remove data identified by the value of its id payload field from the projection.

user.graphql
type User
    @upsertOn(...)
    @removeOn(
        on: {
            topic: "userManagement"
            eventTypes: ["removeUser"]
        }
        identifyBy: { payload: ["id"] }
    ) {
    // ...
}

Arguments

You can use the following arguments on the @removeOn directive directly:

ArgumentDescription
onrestrict deletions of the projection
identifyByspecify how the identifier of the data is generated
filterBydelete entries from the projection by a filter

The arguments and their respective attributes are described in the following sections.

Argument on

The on argument restricts deletions of the projection to specific events. You can use eventTypes or topic to filter the events.

ArgumentDescription
eventTypesrestrict deletions to the projection to a list of event types
topicrestrict deletions to the projection to a topic string

Argument identifyBy

The identifier can consist of one or more elements taken from the event attributes or event payload. These elements will be concatenated into a string where the elements are separated by a - character.

ArgumentDescription
attributesspecify a list of attributes that are part of the identifier
payloadspecify a list of event payload fields that are part of the identifier

When using both attributes and payload, the attributes will be listed first in the identifier, followed by the payload fields. See the example below for clarification.

The @removeOn directive in the following example will delete all events on an event type called removeUser. Every ID in this example starts with the prefix stream- and is followed by a value from the payload. Assuming the payload is {"id": "uuid"}, the ID of the deleted field will be stream-uuid.

@removeOn(
    on: {
        topic: "userManagement"
        eventTypes: ["removeUser"]
    }
    identifyBy: { attributes: ["stream"], payload: ["id"] }
)

Available Event Attributes

The events to trigger a deletion can be filtered using the following attributes:

AttributeDescription
idthe identifier of the event
tenantIdthe identifier of the tenant
topicthe topic to which the event was published to
typename of the event type
streamname of the used stream
correlationIdcorrelation identifier
causationIdcausation identifier
reasonthe reason why the event was published

Argument filterBy

Alternative to the identifyBy argument, you can use the filterBy argument to specify a filter that determines which data should be removed from the projection.

user.graphql
type User
    @removeOn(
        on: {
            topic: "userManagement"
            eventTypes: ["removeUser"]
        }
        filterBy: { fields: [{
            projectionField: "name"
            operation: "equals"
            type: "String"
            eventField: "userName"
        }] }
    ){
    // ...
}

This example shows how to use the filterBy argument to remove data from the projection based on a filter. In this case, the removeUser event will remove data from the projection if the name field of the projection matches the userName field of the event.

Types and operations

TypeAllowed operations
IDequals, notEquals, in, notIn
[ID]inArray, notInArray, lengthEq, lengthNotEq, lengthGt, lengthGtOrEq, lengthLt, lengthLtOrEq, empty, notEmpty
Stringequals, notEquals, equalsCaseInsensitive, notEqualsCaseInsensitive, in, notIn, contains, notContains, containsCaseInsensitive, notContainsCaseInsensitive
[String]inArray, notInArray, lengthEq, lengthNotEq, lengthGt, lengthGtOrEq, lengthLt, lengthLtOrEq, empty, notEmpty
Fileequals, notEquals, in, notIn
DateTimeequals, notEquals, in, notIn, before,beforeOrAt,after,atOrAfter
[DateTime]inArray, notInArray, lengthEq, lengthNotEq, lengthGt, lengthGtOrEq, lengthLt, lengthLtOrEq, empty, notEmpty
Intequals, notEquals, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual
[Int]inArray, notInArray, lengthEq, lengthNotEq, lengthGt, lengthGtOrEq, lengthLt, lengthLtOrEq, empty, notEmpty
Floatequals, notEquals, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual
[Float]inArray, notInArray, lengthEq, lengthNotEq, lengthGt, lengthGtOrEq, lengthLt, lengthLtOrEq, empty, notEmpty
Booleanequals, notEquals

The in and notIn filters require an array as value. The inArray and notInArray filters allow arrays or single values.