-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Cart query always return blank result #333
Comments
@kenchoong Sounds like your missing the WooCommerce Session JWT. It allows WooCommerce keeps track of the session. See this React/Apollo example for more info on implementation. Sorry, about the lack of documentation. I'm actually working on it, but it's slow going. |
@kidunot89 thanks a lot for your help.. You doing great plugin. As state in the example provided, so means that I need to add |
Yes, it works like an HTTP Authorization token when using a plugin like WPGraphQL-JWT-Authentication. The Apollo middleware will pass the WooCommerce session token if it's found in localStorage or whatever storage method you prefer and it will be passed as an HTTP request header on every request. The afterware will retrieve and overwrite the token with any new token it may receive in a That's if your middleware and afterward are configured like in the example. When the request is being processed by the server, WooGraphQL retrieves and decodes the token, then passing the session user ID to WooCommerce and the session data is identified in the data and loaded. If the token is updated it will send the updated token in a HTTP response header, when the mutation is processed. Small note: Currently only WooCommerce Session data includes any customer data for users not registered and cart data. Session data is periodically deleted with WP-Cron if I'm not mistaken. Also if you wish to login and/or register customers from/to the WordPress database, you have to use a plugin for user authentication like WPGraphQL-JWT-Authentication as well as the WooCommerce sessions. |
Wow.. thanks a lot.. Now I have the basic concept, let me try this later.. Thank you very much |
It works after implement the Middleware and Afterware into ApolloClient.. Thank you very much!! |
@kidunot89 I providing JWT token but session not work for AddToCart, getCart and CustomerQuery......Please help me. |
is someone still follwoing here? @kidunot89 |
@AmirAmArA have you read the docs on configuring the client and updated to the latest version of all WPGraphQL/WooGraphQL plugins |
I have a mutation to Add to cart like this:
This is Get Cart query:
Then I call this mutation like this:
As you can see above, I
refetch()
theGET_CART
query when theonCompleted()
of theaddToCart
mutation.What I expect:
Therefore what I expect should be, initial it will be a blank cart(subtotal 0.00) , then when successful mutation, it will have the product inside it.
End Result:
But end up, everytime the
GET_CART
query will return the blank cart even theaddToCart
mutation is successful.But weird thing is, when I using GraphiQL in
wp-admin
dashboard, it works as expected in What I expect section . If I having the successful mutation in GraphiQL, I get the data in cart using theGET_CART
query.So what I missing out? Cause I can't find any documentation on this. Cause when I checked the docs about the cart, I found this, https://woographql.com/guides/create-react-app/3-creating-the-cart which I didnt see any documentation.
Any help will be appreciated.
@kidunot89
The text was updated successfully, but these errors were encountered: