Closed
Description
Make the destination*cart*id
argument optional in the mergeCarts
mutation
Why
PR
#30633
This came up in a discussion with [@sirugh](https://github.com/sirugh] from the [pwa-studio
|https://github.com/magento/pwa-studio) team.
When a user logs in (creates a new token), one of the first things the UI needs to do is merge the current guest cart (if items are present) into the customer account's cart.
If destination*cart*id
is required, this requires 3 round trips:
- Call for
Mutation.generateCustomerToken
- Call for
Query.cart
to get customer cart ID - Call for
Mutation.mergeCarts
to merge guest cart ID into customer cart
Because a customer can only have a single cart, and this API only works for authenticated users, destination*cart*id
is an unnecessary requirement here. If we make it optional, the login cart upgrade for UI can happen in a single request:
1. Mutations run serially, in-order. So `mergeCarts` will only execute
1. if `generateCustomerToken` succeeds
mutation LoginAndMergeCarts($email: String!, $password: String!, $guestCartID: String!) {
generateCustomerToken(email: $email, password: $password) {
token
}
mergeCarts(source*cart*id: $guestCartID) {
ID
}
} {code}
## Proposed Change
{code:java}
type Mutation {
- mergeCarts(source*cart_id: String!, destination_cart*id: String!): Cart!
</ins> mergeCarts(source*cart_id: String!, destination_cart*id: String): Cart!
} ```
<ins>**Approved Design**</ins>
<https://github.com/magento/architecture/blob/mergeCarts-optional-destination/design-documents/graph-ql/coverage/mergeCarts-optional-destination.md>