wpengine / faustjs

Faust.js™ - The Headless WordPress Framework
https://faustjs.org
Other
1.43k stars 131 forks source link

Bug: getApolloAuthClient function not working correctly when usePersistedQueries is enabled and using PersistedQueriesPlugin #1540

Closed tuanfront-end closed 9 months ago

tuanfront-end commented 1 year ago

Wishing everyone a good day. The problem I'm having is that it seems that getApolloAuthClient() is not working correctly when I enable usePersistedQueries: true in the config file and use the PersistedQueriesPlugin plugin (https://github.com/wp-graphql/wpgraphql.com/blob/master/src/plugins/PersistedQueriesPlugin.js).

I got error 414 when my query seems long, then I enabled usePersistedQueries: true but it didn't work, I searched and used the PersistedQueriesPlugin plugin. After that, the 414 error went away, but the problem was that the queries that needed to authenticate the client getApolloAuthClient() returned null.

Steps To Reproduce

I tried again with a new Faustjs project and the problem still occurs.

  1. Initialize new faustjs project
  2. Configure to WordPress site and write 1 simple query getViewer, getApolloAuthClient works fine and getViewer returns data as expected.
  3. Enable usePersistedQueries: true in the file faust.config and create a PersistedQueriesPlugin plugin using this code - https://github.com/wp-graphql/wpgraphql.com/blob/master/src/plugins/PersistedQueriesPlugin.js
  4. Recheck the getViewer query returns null, while isAuthenticated still is true.

    The current behavior

    The getViewer query returns null, while isAuthenticated still is true

The expected behavior

The getViewer query must returns viewer data correctly when isAuthenticated is true.

tuanfront-end commented 1 year ago

@theodesp @jasonbahl Would be very grateful for any great help from you guys. Thanks in advance

blakewilson commented 1 year ago

Hi @tuanfront-end, thank you for your issue!

With the usePersistedQueries option set to true, no plugin is required to enable persisted queries. I believe @jasonbahl was using that plugin as that was the only way to enable persisted queries before we introduced the usePersistedQueries flag.

I created an example project with persisted queries enabled while fetching authenticated content with getApolloAuthClient and was able to get the proper data back:

Screenshot 2023-08-21 at 11 38 17 AM

You can check that public repo out here:

https://github.com/blakewilson/faust-auth-persisted-queries

Additionally, here is the specific commit with those changes (I cloned the Faust example project; this commit contains the only changes from the example):

https://github.com/blakewilson/faust-auth-persisted-queries/commit/ee0edffe8ac2e5d04f6befb9bc96f7a0cbdc4522

If you are still experiencing this issue, could you please create a reproducible repo that we can use to debug? Thanks!

blakewilson commented 1 year ago

Hi @tuanfront-end,

We may have uncovered a bug relating to persisted queries and I'm curious if it's related to what you are experiencing here.

Could you try running the latest nightly Faust build and see if it fixes the issue you are seeing?

You can do so by running:

npm install @faustwp/core@canary
tuanfront-end commented 1 year ago

Thank you so much @blakewilson, I am going to check it out right now.

MattOndo commented 1 year ago

Hey there! I'm experience the same exact issue. After installing @faustwp/core@canary the issue seems to be resolved. I do still occasionally get this error though:

ApolloError: Persisted queries are not supported by this server

I've heard conflicting info on whether WPGraphQL Smart Cache, so have been enabling/disabling that plugin to see if that's causing the error but doesn't seem to matter. As of right now, the plugin is installed & activated and am seeing this error message.

blakewilson commented 1 year ago

Hey @tuanfront-end, were you able to confirm if this canary release fixed the issue you were seeing?

blakewilson commented 1 year ago

@MattOndo Glad to see the issue you were facing seems to have been resolved!

As for the ApolloError: Persisted queries are not supported by this server error message, from my understanding, you'll only see that when you don't have WPGraphQL Smart Cache enabled.

So if you do have the plugin enabled and are still seeing this, could you please open a new issue with steps to reproduce?

tuanfront-end commented 1 year ago

@blakewilson I'm very sorry that I wanted to check further with the queries so I didn't respond right away. So far everything seems to be working fine. Thank you so much for your work 🩷

mindctrl commented 9 months ago

It looks like everything was resolved here. 🎉 I'm going to close the issue. If you're still experiencing issues, feel free to re-open.