Cart mutation response error

Solved

Cart mutation response error

AlexanderWeb
Shopify Partner
16 0 2

I have the following UI where I want to increment o decrement the quantity of a product and update the cart immediately.

 

Screenshot 2024-01-02 at 16.29.00.png

 

I am using the following mutation:

 

 

 

...
const handleUpdateExistingCartLines =() =>

...

const updateCartMutation = gql`
${CART_COMMON_FIELDS}
mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineInput!]!) {
cartLinesUpdate(cartId: $cartId, lines: $lines) {
cart {
...cartProducts
}
}
}
`;

const variables = {
cartId,
lines: [
{
quantity: parseInt(quantity),
id: mainId,
},
],
};

try {
return await graphQLClient.request(updateCartMutation, variables);
} catch (error: any) {
throw new Error(error);
}
}

 

 

 

 

I than use the above mutation by invoking the following function:

 

handleUpdateExistingCartLines({
  quantity: (el.quantity + 1).toString(),
  mainId: el.merchandise.id,
});
 
I would like to use the same function to increment or decrement the quantity of an existing item in the cart.
 
This is the variables object that is sent with the mutation:
 
Screenshot 2024-01-02 at 16.34.07.png
 
but I get the following error:
 
Screenshot 2024-01-02 at 16.27.34.png
 
any help would much appreciated. Thank you
Accepted Solution (1)

Liam
Shopify Staff
2873 312 820

This is an accepted solution.

Hi Alexander,

 

This sounds like a variable mismatch in your code - and looks slightly similar to this GitHub issue. If you follow a similar approach to what is advised there, can you resolve this?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Reply 1 (1)

Liam
Shopify Staff
2873 312 820

This is an accepted solution.

Hi Alexander,

 

This sounds like a variable mismatch in your code - and looks slightly similar to this GitHub issue. If you follow a similar approach to what is advised there, can you resolve this?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog