Mutation
addOrderItem
Adds a new item to an existing order. Only orders in PENDING status can be modified. Stock is reserved for the added item.
Signature
mutation { addOrderItem(orderId: ID!, input: AddOrderItemInput!): AddOrderItemPayload! }
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
orderId |
ID! |
Yes | The unique identifier of the order to modify |
input |
AddOrderItemInput! |
Yes | The item details including product ID and quantity |
Return Type
AddOrderItemPayload!
Complexity: 4
Examples
Query
mutation AddOrderItem($orderId: ID!, $input: AddOrderItemInput!) {
addOrderItem(orderId: $orderId, input: $input) {
order {
id
status
totalAmount
items {
product {
id
name
}
quantity
unitPrice
}
}
addedItem {
product {
id
name
}
quantity
unitPrice
}
errors {
field
message
}
}
}
Variables
{
"orderId": "order_abc123",
"input": {
"productId": "prod_ghi789",
"quantity": 3
}
}
Response
{
"data": {
"addOrderItem": {
"order": {
"id": "order_abc123",
"status": "PENDING",
"totalAmount": "389.96",
"items": [
{
"product": {
"id": "prod_abc123",
"name": "Wireless Bluetooth Headphones"
},
"quantity": 2,
"unitPrice": "149.99"
},
{
"product": {
"id": "prod_ghi789",
"name": "Screen Protector Pack"
},
"quantity": 3,
"unitPrice": "29.99"
}
]
},
"addedItem": {
"product": {
"id": "prod_ghi789",
"name": "Screen Protector Pack"
},
"quantity": 3,
"unitPrice": "29.99"
},
"errors": null
}
}
}