-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
forceFetch without using node (without id) #858
Comments
perhaps similar to #742? |
@legomind did you eventually figure out the problem or find a workaround? Facing a similar scenario at the moment. |
I found a very hacky workaround. Basically, I wrapped the User Type in a ViewerType and gave viewer an id of 1, even when user is null. |
I had the same idea but feels really wrong 🐵 |
@legomind, @schickling - are logged out users able to access any GraphQL data in your apps? An approach we often use is to not even query the GraphQL server until the user is logged in - this avoids having fields start out Another approach going forward will be to have one RelayContext (currently not public API yet) before the user logs in to store unauthenticated data, and then create a new context after the user logs in. In the meantime, though, could you work around this by not issuing queries until login? |
@schickling Yes, it feels very, very wrong. @josephsavona Currently, authentication is actually performed using mutations (I just updated the original post), so that approach would not work. Even if I was to move authentication out of graphql, how would I prevent the initial queries? Just avoid rendering a RootContainer? |
@legomind Yup. |
Thanks for the clarification @josephsavona! Is there any rough timeline for the multiple RelayContext feature? |
Soon-ish - I posted an update on the main task #558 |
We added support for multiple contexts/environments a few releases back, which addresses the logout or change-user case. |
I have an app that uses Hawk for authentication (hueniverse/hawk)
The authentication is driven using a plain http endpoint
/api/auth
Edit: I have moved authentication to a graphql mutation
My graphQL endpoint has the following relay compatible schema:
So when an unauthenticated user first visits the site, the following query is run:
Since this query is lacking Hawk credentials in the http headers, the above query returns null, causing the app to render a login form.
Upon login, the app will make a call to
/api/auth
in order to get credentials for future graphQL callsEdit: Now using mutations instead
Then the login page will call
this.props.relay.forceFetch()
in order to update the required user data.However, since the initial call returns
null
relay simply skips the graphQL call because it does not have an id querynode
with.If I refresh the entire page, the
viewer
prop contains the user data of the logged in user, and if I login again, the following query runs:Conversely, a similar issue arises when refreshing data after logout.
this.props.relay.forceFetch()
runs the abovenode
query instead of queryingviewer
.How can I force relay to use the inital query to refetch the currently logged in user?
The text was updated successfully, but these errors were encountered: