Skip to content

[Atwix]Make the destination_cart_id argument optional in the mergeCarts mutation #30469

Closed
@magento-engcom-team

Description

@magento-engcom-team

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:

  1. Call for Mutation.generateCustomerToken
  2. Call for Query.cart to get customer cart ID
  3. 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> 
  

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions