wp-graphql / wp-graphql-woocommerce

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

An error from the plugin causes the application to disconnect from Wordpress using GraphQL and Apollo Client #682

Closed WojciechPolec closed 9 months ago

WojciechPolec commented 1 year ago

Describe the bug

We have a problem in an online store using the WPGraphQL WooCommerce (WooGraphQL) plugin. It manifests itself in such a way when we want to add a product to the basket when we are logged in and authorized, we cannot do it because on the GraphQL and Wordpress side we get ERROR, which causes us to lose communication and the operation cannot be performed.

Error from debug.log: "PHP Fatal error: Uncaught GraphQL\Error\UserError: Woo session transaction executed out of order in /public_html/wp-content/plugins/wp-graphql-woocommerce-2/includes/utils/class-session-transaction-manager.php:220"

I edited the plugin and commented out this line in the plugin code. Then everything started working as it should.

Expected behavior

Operations performed via GraphQL and Apollo Client using the wp-graphql-woocommerce plugin should not lose connection due to an error. The code under the path /public_html/wp-content/plugins/wp-graphql-woocommerce-2/includes/utils/class-session-transaction-manager.php:220 breaks the connection and makes it impossible to perform other operations. Commenting out this solved the problem for me temporarily.

Plugin Versions and other

Additional context

Is this a bug? Is the problem elsewhere? I temporarily solved the problem by commenting out some plugin code but this is not an optimal solution and problematic if we want to update the plugin.

vorasudh commented 1 year ago

I am also facing the exact same issue - #684. I will take your suggestion and comment out the line. From what I observed, the issue has nothing to do with Apollo Client. I tried to execute the mutation via Postman and it gives me the same error.

vorasudh commented 1 year ago

I tried commenting out the code, but this results in all requests receiving a 403 response code. This basically means, no data is displayed on the webpage.

WojciechPolec commented 1 year ago

Anybody got any ideas how to solve this problem? Or some plugin update will solve it?

C4MS commented 1 year ago

I just experienced the same issue, after running out of memory while doing some tests, the user doing the request will receive the same error on all further requests by the server, I had to remove all transients as a quick fix which is not ideal on a production site wp transients delete --all

kidunot89 commented 1 year ago

@C4MS @WojciechPolec @vorasudh Are you correctly setting the sessionToken from under the customer query in the woocommerce-session HTTP header in your GraphQL request. It should be format like the Session ${sessionToken}. Remember always prefix the token with Session.

query {
  customer {
    sessionToken
  }
}
kidunot89 commented 1 year ago

@C4MS @WojciechPolec @vorasudh Any updates on this?