Cancel request with trigger.before

Is it possible to cancel a mutation conditionally inside of a trigger.before function? Specifically I’m trying to create a version of an upsert operation but I’d like to use the trigger.before rather than a resolver so that it’s run no matter where the operation is being triggered (nested or not).

This is my handler. Not returning anything simply creates an empty row.

@kenna
Sorry for the long answer.
You can use simple throw new Error("someErrorText"); in your conditional statement to stop further execution.

2 Likes

Trigger.before is the right approach and simply by adding an Error object to the response array (or using @Fomich’s approach) you’ll be able to cancel the mutation. Make sure you set the trigger to execute both on create, update, and delete operations if each of them are relevant to what you’re working on!

Trigger response docs for error example: Triggers - 8base Documentation

1 Like