The first piece of functionality our cart needs is to allow users to add their chosen product variants to it. Thinking about how this will be invoked from the UI, there are two things that could happen when a user clicks the Add to cart button from the product details page. First, if the chosen product variant does not yet exist in the cart, a new cart item is pushed to the array; second, if there is already a matching variant in the cart, we need to increment its quantity.
Adding products to the cart
Creating the mutations
Now, we could create a single mutation that contains the logic required to work out whether the selected product variant already exists in the cart or not, then either push a new item or update an existing...