r/graphql • u/[deleted] • Feb 21 '20
Authentication with Apollo Client?
Could someone look into this? I was unable to copy paste properly formatted code here
https://stackoverflow.com/questions/60346591/graphql-authentication-with-react-typescript
0
Upvotes
10
u/danielrearden Feb 21 '20 edited Feb 22 '20
You need to call your mutation using the
useMutationhook or theMutationcomponent, await the result of the mutation, use the result to set the value oftokenin local storage and then either trigger a refetch of the relevant queries or callclient.resetStore.However, there's a number of other things off about your code (using string interpolation instead of variables, embedding the client directly inside your component). Based on that and the previous question you asked on SO, I would suggest starting smaller and working through Apollo's extensive documentation and examples, beginning with this.