reym
Projections/Schema/Object

@dangerouslyUpsertOn

@dangerouslyUpsertOn complements the @upsertOn directive.

There are cases where you might want your projection to react to events from multiple topics. In such cases, you can use the @dangerouslyUpsertOn directive to upsert data into the projection based on events from multiple topics.

Possible Inconsistencies

Using @dangerouslyUpsertOn can lead to inconsistencies in your projection. The order of events is only guaranteed within a single topic, not across multiple topics. Therefore it might happen that all events of topic A are applied before all events of topic B, even if the event from topic B was published before the event from topic A. If this is not a problem for your projection, you can use @dangerouslyUpsertOn to upsert data into the projection based on events from multiple topics.

Example

In the following case the updateUser event from the userManagement topic will upsert data to the dataset identified by the value of its id payload field. The updateUser event will upsert data to the dataset identified by its userId payload field.

user.graphql
type User
    @upsertOn(
        on: {
            topic: "userManagement"
            eventTypes: ["updateUser"]
        }
        identifyBy: { payload: ["id"] }
    )
    @dangerouslyUpsertOn(
        on: {
            topic: "roleManagement"
            eventTypes: ["updateUser"]
        }
        identifyBy: { payload: ["userId"] }
    ) {
    // ...
}

As you can see in this example, the updateUser events from two different topics are used to upsert data into the projection.

For more information, please see the upsertOn directive.

On this page