2019-08-12 16:04:16 +02:00
|
|
|
import { ApolloCache } from 'apollo-cache';
|
|
|
|
import { NormalizedCacheObject } from 'apollo-cache-inmemory';
|
|
|
|
|
|
|
|
export function buildCurrentUserResolver(cache: ApolloCache<NormalizedCacheObject>) {
|
|
|
|
cache.writeData({
|
|
|
|
data: {
|
|
|
|
currentUser: {
|
|
|
|
__typename: 'CurrentUser',
|
|
|
|
id: null,
|
|
|
|
email: null,
|
|
|
|
isLoggedIn: false,
|
|
|
|
},
|
2019-01-18 14:47:10 +01:00
|
|
|
},
|
2019-08-12 16:04:16 +02:00
|
|
|
});
|
2019-01-18 14:47:10 +01:00
|
|
|
|
2019-08-12 16:04:16 +02:00
|
|
|
return {
|
|
|
|
updateCurrentUser: (_, { id, email, isLoggedIn }, { cache }) => {
|
|
|
|
const data = {
|
|
|
|
Mutation: {
|
2019-01-18 14:47:10 +01:00
|
|
|
currentUser: {
|
|
|
|
id,
|
|
|
|
email,
|
2019-04-01 11:49:54 +02:00
|
|
|
isLoggedIn,
|
2019-01-18 14:47:10 +01:00
|
|
|
__typename: 'CurrentUser',
|
|
|
|
},
|
2019-08-12 16:04:16 +02:00
|
|
|
},
|
|
|
|
};
|
2019-01-18 14:47:10 +01:00
|
|
|
|
2019-08-12 16:04:16 +02:00
|
|
|
cache.writeData({ data });
|
2019-01-18 14:47:10 +01:00
|
|
|
},
|
2019-08-12 16:04:16 +02:00
|
|
|
};
|
2019-08-13 08:43:37 +02:00
|
|
|
}
|