Subscription
inventoryUpdated
Subscribes to real-time inventory updates for a specific product or all products. Emits events when stock quantities change due to orders, restocking, or manual adjustments.
Signature
subscription { inventoryUpdated(productId: ID, lowStockThreshold: Int): InventoryUpdatedEvent! }
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
productId |
ID |
No | Optional product ID to filter updates. If not provided, receives updates for all products. |
lowStockThreshold |
Int |
No | Optional threshold to only receive updates when stock falls below this level |
Return Type
InventoryUpdatedEvent!
Complexity: 2
Examples
Query
subscription OnInventoryUpdated($productId: ID, $lowStockThreshold: Int) {
inventoryUpdated(productId: $productId, lowStockThreshold: $lowStockThreshold) {
product {
id
name
stockQuantity
}
previousQuantity
newQuantity
changeReason
changedAt
isLowStock
}
}
Variables
{
"productId": "prod_abc123",
"lowStockThreshold": 50
}
Response
{
"data": {
"inventoryUpdated": {
"product": {
"id": "prod_abc123",
"name": "Wireless Bluetooth Headphones",
"stockQuantity": 45
},
"previousQuantity": 50,
"newQuantity": 45,
"changeReason": "ORDER_PLACED",
"changedAt": "2024-06-21T10:15:00Z",
"isLowStock": true
}
}
}