Skip to content
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

Trouble with QL Session Handler #208

Closed
ardiewen opened this issue Jan 6, 2020 · 2 comments
Closed

Trouble with QL Session Handler #208

ardiewen opened this issue Jan 6, 2020 · 2 comments

Comments

@ardiewen
Copy link
Contributor

ardiewen commented Jan 6, 2020

Hi there,

I'm having some trouble implementing the QL Session Handler example as described in #88 in order to support persistent cart sessions for guest checkouts.

I have created a minimal sandbox environment to illustrate the problem here: https://codesandbox.io/s/crazy-hugle-sm1eb

Expected Behaviour:

  1. User initiates a cart mutation via the Add To Cart button, and receives a 200 response.
  2. If a session doesn't exist, a new session is initialized and stored in local storage (per example).
  3. Once the session is created, subsequent clicks of the button will continue incrementing the item in the cart.

Actual Behaviour:

  1. User initiates a cart mutation and receives a successful 200 response.
  2. Doesn't appear that anything is added to localStorage.
  3. Additional clicks of the button still continue to receive 200 response, but does not increment the quantity in cart.

Additional Notes:

Using the WP GraphiQL plugin to do this on my WP backend appears to work fine.
Screen Shot 2020-01-05 at 10 48 23 PM

Any insights would be appreciated!

@ardiewen
Copy link
Contributor Author

ardiewen commented Jan 6, 2020

Update: I've combed through the client-side code and there doesn't seem to be anything wrong there.

When reviewing the request/response data, it appears that woocommerce-session header isn't being passed back to the client (and therefore not being passed to localStorage).

Instead, it looks like cookies are being set, which suggests the backend doesn't think this is a valid graphql request?

Response Headers (Source)
HTTP/1.1 200 OK
Date: Mon, 06 Jan 2020 15:45:47 GMT
Server: Apache/2.4.29 (Ubuntu)
Set-Cookie: woocommerce_items_in_cart=1; path=/
Set-Cookie: woocommerce_cart_hash=8aca1a16b1132bb5d1137ad3d4334de1; path=/
Set-Cookie: wp_woocommerce_session_adccfeefdeb3b9f4b769dbf554e769f0=dff4a8daa38e838cb9216494872e95e4%7C%7C1578498347%7C%7C1578494747%7C%7C617471f18101a4d82f4c81526b582b70; expires=Wed, 08-Jan-2020 15:45:47 GMT; Max-Age=172800; path=/; HttpOnly
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Authorization, Content-Type, X-JWT-Auth, X-JWT-Refresh, woocommerce-session
Access-Control-Max-Age: 600
X-Robots-Tag: noindex
X-Content-Type-Options: nosniff
X-hacker: If you're reading this, you should visit github.com/wp-graphql and contribute!
Access-Control-Expose-Headers: X-JWT-Refresh, woocommerce-session
Set-Cookie: woocommerce_items_in_cart=1; path=/
Set-Cookie: woocommerce_cart_hash=77cad6d2d6064978b735bb6d9da59686; path=/
Set-Cookie: wp_woocommerce_session_adccfeefdeb3b9f4b769dbf554e769f0=dff4a8daa38e838cb9216494872e95e4%7C%7C1578498347%7C%7C1578494747%7C%7C617471f18101a4d82f4c81526b582b70; expires=Wed, 08-Jan-2020 15:45:47 GMT; Max-Age=172800; path=/; HttpOnly
Content-Length: 375
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8

This is a standard Apollo client request via the codesandbox mentioned above. On the backend, I have not made any customizations, e.g. defining NO_QL_SESSION_HANDLER.

@ardiewen
Copy link
Contributor Author

ardiewen commented Jan 6, 2020

Update: I was able to resolve this by resetting the entire backend and updating to the following plugin versions:

WP GraphQL v0.5.1 (previously 0.4.2)
WooGraphQL v0.3.2

@ardiewen ardiewen closed this as completed Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant