ClearCartMutation
Description
Deletes the cart by its ID. This mutation allows you to completely clear a cart, removing all items and associated data.
Endpoint
mutation clearCart($cartId: String!) {
clearCart(cartId: $cartId)
}
Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
| cartId | String | Yes | The unique identifier of the cart to clear. This ID is obtained from createGuestCart or createCustomerCart mutations. |
Return Values
The mutation returns a Boolean value:
| Type | Description |
|---|---|
| Boolean | Returns true if the cart was successfully cleared, or false if the operation failed. |
Usage Example
mutation {
clearCart(cartId: "abc123")
}
Example Response
{
"data": {
"clearCart": true
}
}
Notes
- This operation permanently removes all items from the cart and cannot be undone.
- The cart ID remains valid after clearing the cart, so you can continue to use the same cart ID for new operations.
- If you want to completely abandon a cart and start fresh, you may want to create a new cart using the
createGuestCartorcreateCustomerCartmutation instead. - If the cart ID is invalid or the cart has already been converted to an order, the mutation may return
false.