Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Cart mutation response error

Solved

Cart mutation response error

AlexanderWeb
Shopify Partner
20 0 3

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
Community Manager
3108 344 899

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
Community Manager
3108 344 899

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