pub struct BeforeMutationChain {
pub triggers: Vec<BeforeMutationTrigger>,
}Expand description
Chain of before-mutation triggers for a single mutation.
Executes multiple before:mutation triggers in declaration order.
Each trigger can modify the input and pass it to the next trigger,
or abort the mutation by returning an error.
§Execution Semantics
- Synchronous: blocks the mutation (execution is on the hot path)
- Sequential: triggers execute in declaration order
- Propagating: each trigger receives the modified input from previous trigger
- Short-circuit: first abort stops the chain immediately
- Default timeout: 500ms per trigger (shorter than general 5s default)
- Side-effects: any side-effects from aborted triggers are NOT rolled back
§Example
ⓘ
let chain = BeforeMutationChain {
triggers: vec![
validateInput, // checks required fields
checkDuplicates, // checks uniqueness
auditLog, // logs the attempt
]
};
let result = chain.execute(input, &observer).await?;
match result {
Proceed(modified) => { /* mutation continues */ }
Abort(error) => { /* mutation cancelled */ }
}Fields§
§triggers: Vec<BeforeMutationTrigger>Triggers in declaration order.
Implementations§
Source§impl BeforeMutationChain
impl BeforeMutationChain
Sourcepub async fn execute<H>(
&self,
input: Value,
modules: &HashMap<String, FunctionModule>,
observer: &FunctionObserver,
host: &H,
limits: ResourceLimits,
) -> Result<BeforeMutationResult>where
H: HostContext + ?Sized,
pub async fn execute<H>(
&self,
input: Value,
modules: &HashMap<String, FunctionModule>,
observer: &FunctionObserver,
host: &H,
limits: ResourceLimits,
) -> Result<BeforeMutationResult>where
H: HostContext + ?Sized,
Execute the before-mutation chain with the given input.
Runs all triggers in declaration order. Each trigger receives the
(possibly modified) output of the previous trigger as its input.
The first Abort short-circuits the chain.
§Convention for function return values
Functions signal their intent via the returned JSON object:
{"abort": "message"}→ abort the mutation withmessage{"input": {...}}→ proceed with modified input- Any other value (or
null) → proceed with the input unchanged
§Errors
Returns Err if a trigger’s function name is not found in modules, or if
function execution itself returns an error.
Trait Implementations§
Source§impl Clone for BeforeMutationChain
impl Clone for BeforeMutationChain
Source§fn clone(&self) -> BeforeMutationChain
fn clone(&self) -> BeforeMutationChain
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BeforeMutationChain
impl RefUnwindSafe for BeforeMutationChain
impl Send for BeforeMutationChain
impl Sync for BeforeMutationChain
impl Unpin for BeforeMutationChain
impl UnsafeUnpin for BeforeMutationChain
impl UnwindSafe for BeforeMutationChain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more