Skip to content

EmptyCart and RemoveItemsFromCart mutation don't work #454

Closed
@believelody

Description

@believelody

Describe the bug
Hi guys, I have a big weird problem with emptyCart and removeItemsFromCart mutations. I'm using react as wordpress theme (so I'm working directly in wordpress folder) with create-react-wptheme. I copied -> pasted an older standalone react project with WP as backend inside of this react wordpress theme. It's basically the same thing ! THEN...
The problem is:

  • I add products into cart, everything work fine;
  • I update item quantity, it's okay;
  • If I have at least 2 products and I delete one of them, it works, item is correctly deleted, cart is updated;
  • Now, if I have only ONE item in cart or want to delete all items...then nothing happen;

I 'm using the @apollo/client library so when I use a mutation with useMutation, I also call refetch method from useQuery to refetch cart after some update. This "refetch" works when I add an item or update a existing item in cart like I said above. I don't understand at all why for removing last item or deleting all, refetch gives me back a non updated cart.

Expected behavior
These two mutations work fine in graphiql in admin dashboard (I mean when I query cart after calling one of these two, my cart is updated), so I expect the same in my app.

Screenshots

This is how I proceed. I call "refetch" in "onCompleted" callback provided by useMutation
image

As you can see in this screenshot, removeItemsFromCart mutation seems to work but refetch doesn't bring me back the correct updated cart. It's very strange.
image

This last screenshot is my apollo configuration
image

Desktop (please complete the following information):

  • OS: Ubuntu
  • Version 18

Plugin Versions

  • WooGraphQL Version: 0.5.1
  • WPGraphQL Version: 1.1.5
  • WordPress Version: 5.5.3
  • WooCommerce Version: 5.0.0

Additional context
The WEIRDEST thing is...Everything work perfectly in my standalone react project (the one I copied to use directly in wordpress folder).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions