Rebuild Inventory Stock
Rebuild Inventory Stock Mutation
Audience: Programmer
Rebuilds the entire inventory stock table for the current tenant. This administrative operation recalculates all stock figures from the ground truth of executed movements, correcting any drift caused by bugs, out-of-order movement processing, or data migrations.
Arguments
This mutation takes no arguments. It operates on the tenant determined by the request context.
Return Type
RebuildStockOutput - Indicates whether the stock rebuild completed successfully.
success
Boolean!
Whether the stock table was successfully rebuilt
Authorization
This mutation requires the admin role. Calling it without admin privileges will return an authorization error.
Usage Example
mutation {
rebuildInventoryStock {
success
}
}Expected Response
JavaScript Example
When to Use
This mutation should be used in the following scenarios:
Stock drift: When stock figures no longer match the expected totals derived from executed movements
Bug recovery: After a bug has caused incorrect stock calculations that need correction
Out-of-order movements: When movements were processed in an unexpected order, leading to inconsistent stock levels
Data migration: After importing or migrating movement data from an external system
Periodic reconciliation: As part of a scheduled maintenance routine to ensure stock accuracy
What Happens During Execution
Authorization check: Verifies the caller holds the admin role for the current tenant
Transaction: Opens a database transaction to ensure atomicity
Rebuild: Calls the stock service to recalculate all stock records from executed movements
Commit: If successful, commits the rebuilt stock table
The operation is atomic -- it either fully completes or rolls back entirely.
Error Cases
Unauthorized: The caller does not have the admin role for the tenant
Internal error: A failure occurred during the stock rebuild (the transaction is rolled back)
Notes
This is an admin-only operation and is not intended for regular application use
The mutation operates within a single database transaction for consistency
No arguments are needed because it rebuilds the entire stock table for the tenant
The operation may take longer on tenants with large numbers of movements
Stock records are recalculated from the source of truth (executed movements and transactions)
Consider running this during low-traffic periods to minimize impact on concurrent operations
Last updated
Was this helpful?
