ClientState.js
700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gql from "graphql-tag";
const clientQuery = gql`
{
isLoggedIn @client
}
`;
export const defaults = {
isLoggedIn: Boolean(localStorage.getItem("token") || false),
};
export const resolvers = {
Mutation: {
logUserIn: (_, { token }, { cache }) => {
localStorage.setItem("token", token);
cache.writeData({
data: {
isLoggedIn: true,
},
});
return null;
},
logUserOut: (_, __, { cache }) => {
localStorage.removeItem("token");
cache.writeData({
data: {
isLoggedIn: false,
},
});
window.location.reload();
return null;
},
},
Query: {
clientQuery,
},
};