Problem with the Storefront GraphQL cartLinesUpdate mutation

Hi!

I’ve been trying to update the quantity of an existing cart line item using the Storefront GraphQL API without success. I get a successful response with the updated cart, except the quantity is unchanged. Interestingly changing the line item attributes in this way works, but changing the quantity does not. Am I missing something? :thinking:

Here’s my query:

mutation updateCartLines($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
  cartLinesUpdate(cartId: $cartId, lines: $lines) {
    userErrors {
      code
    	field
    	message
    }
    cart {
      id
      lines(first: 5) {
          edges {
            node {
              id
              quantity
              attributes {
                key
                value
              }
            }
          }
        }
    }
  }
}

Variables:

{
  "cartId": "[...]",
  "lines": 
      {
        "quantity": 2,
        "id": "[...]"
      }
}

Response:

{
  "data": {
    "cartLinesUpdate": {
      "userErrors": [],
      "cart": {
        "id": "[...]",
        "lines": {
          "edges": [
            {
              "node": {
                "id": "[...]",
                "quantity": 1,
                "attributes": []
              }
            }
          ]
        }
      }
    }
  }
}

Thanks in advance!

Mystery solved! For anyone else that might run into this in the future:

The reason quantity would not update from 1 was because the store only had 1 of that product variant ?‍Trying it on a product variant with a higher quantity, it works as expected. In hindsight this makes total sense, I’m a bit disappointed in myself that it took me several hours to figure out :grin:

3 Likes

You saved me a lot of trouble. I think it would make more sense for this to result in a 400 with appropriate error message.