Overview
Mutation flow:Mutation Handler
Implement a mutation endpoint usinghandleMutateRequest:
Defining Mutators
Basic Mutator
Nested Mutators
Organize mutators by namespace:Transaction API
The transaction object (tx) provides:
Properties
CRUD Operations
Running Queries
Query data within the transaction:Raw SQL Access
Access the underlying database transaction:Validation
Validate input before mutations:Error Handling
Application Errors
ThrowApplicationError for user-facing errors:
Database Errors
Database errors are automatically caught and the transaction is rolled back. Zero Cache will retry transient errors.Out-of-Order Mutations
Zero ensures mutations are processed in order per client. Out-of-order mutations are rejected withOutOfOrderMutation error.
Advanced Patterns
Side Effects
Perform side effects after successful commit:Idempotency
Mutations with the samemutationID are processed only once:
Batch Operations
Process multiple records:Cascading Deletes
Context and Authentication
Access request context in mutators:Testing
Test mutators with a test database:Performance
Connection Pooling
Use connection pooling for better performance:Batch Queries
Fetch related data in one query:Next Steps
- Custom Queries - Transform client queries
- Deployment - Deploy to production