wp-graphql / wp-graphql-woocommerce

Add WooCommerce support and functionality to your WPGraphQL server
https://woographql.com
GNU General Public License v3.0
633 stars 123 forks source link

AddToCart in parallel doesn't work #844

Closed Shazamepool closed 1 month ago

Shazamepool commented 2 months ago

Describe the bug When I make several addToCart in parallel, only the products added by the last addToCart launched will appear in my cart.

To Reproduce 0 - It's easier to reproduce on a slow site 1 - Quickly launch 3 addToCart for different products in parallel with the same woocommerce-session header. 2 - Note in their returns that the cart contains only the product just added. 3 - Send a getCart with the same header and see that only the last product added appears in the cart.

 mutation addToCart($productId: Int!, $quantity: Int) {
    addToCart(input: {productId: $productId, quantity: $quantity}) {
        cart {
            contents {
                nodes {
                    quantity
                }
            }
           total
       }
   }
}

Expected behavior All added products should appear in the cart

Plugin Versions

Additional context The bug was caused by changing the graphql_process_http_request_response action to graphql_mutation_response when upgrading to version 0.19.0 of the plugin.

Shazamepool commented 2 months ago

I solved this problem by modifying the code of the pop_transaction_id function:

kidunot89 commented 2 months ago

@Shazamepool Damn good catch, bro.