-2

I'm trying to update the viewer field of the root node when user logs in with a UpdateUserSessionMutation. However since viewer starts as null and doesn't have an id initially, I'm not able to update the viewer field with the MutaitonPayload using FIELDS_CHANGE.

Oguz Bilgic
  • 3,072
  • 5
  • 33
  • 55
  • I'm not sure why I got downvoted by here is an answer that could help for others: https://github.com/facebook/relay/issues/233 – Oguz Bilgic Nov 19 '15 at 06:53

1 Answers1

0

Mutations are used when you want to update data stored in the DB. User login doesn't change any DB data, so mutation is not the right approach.

viewer is used to represent a currently logged in user. The common practice to keep track of that is an authorization token. When user logs in (this is usually done outside of GraphQL), you'd then include their token with every request. On the server, you'd look at that token, and set the current user as the root viewer node for that request, which you can do using rootValue.

Petr Bela
  • 7,368
  • 2
  • 25
  • 34
  • Well our user sessions are stored in the database... However even if you were correct my question was answered by one of FB developers: https://github.com/facebook/relay/issues/233 – Oguz Bilgic Nov 19 '15 at 06:50
  • The GH issue is about resetting local store. How is that related? – Petr Bela Nov 19 '15 at 14:07