2019-08-12 14:04:16 +00:00
|
|
|
import { ApolloCache } from 'apollo-cache';
|
|
|
|
import { NormalizedCacheObject } from 'apollo-cache-inmemory';
|
2019-09-09 07:31:08 +00:00
|
|
|
import { ICurrentUserRole } from '@/types/current-user.model';
|
2019-08-12 14:04:16 +00:00
|
|
|
|
|
|
|
export function buildCurrentUserResolver(cache: ApolloCache<NormalizedCacheObject>) {
|
|
|
|
cache.writeData({
|
|
|
|
data: {
|
|
|
|
currentUser: {
|
|
|
|
__typename: 'CurrentUser',
|
|
|
|
id: null,
|
|
|
|
email: null,
|
|
|
|
isLoggedIn: false,
|
2019-09-09 07:31:08 +00:00
|
|
|
role: ICurrentUserRole.USER,
|
2019-08-12 14:04:16 +00:00
|
|
|
},
|
2019-01-18 13:47:10 +00:00
|
|
|
},
|
2019-08-12 14:04:16 +00:00
|
|
|
});
|
2019-01-18 13:47:10 +00:00
|
|
|
|
2019-08-12 14:04:16 +00:00
|
|
|
return {
|
2019-08-21 09:25:09 +00:00
|
|
|
Mutation: {
|
2019-09-09 07:31:08 +00:00
|
|
|
updateCurrentUser: (_, { id, email, isLoggedIn, role }, { cache }) => {
|
2019-08-21 09:25:09 +00:00
|
|
|
const data = {
|
2019-01-18 13:47:10 +00:00
|
|
|
currentUser: {
|
|
|
|
id,
|
|
|
|
email,
|
2019-04-01 09:49:54 +00:00
|
|
|
isLoggedIn,
|
2019-09-09 07:31:08 +00:00
|
|
|
role,
|
2019-01-18 13:47:10 +00:00
|
|
|
__typename: 'CurrentUser',
|
|
|
|
},
|
2019-08-21 09:25:09 +00:00
|
|
|
};
|
2019-01-18 13:47:10 +00:00
|
|
|
|
2019-08-21 09:25:09 +00:00
|
|
|
cache.writeData({ data });
|
|
|
|
},
|
2019-01-18 13:47:10 +00:00
|
|
|
},
|
2019-08-12 14:04:16 +00:00
|
|
|
};
|
2019-08-13 06:43:37 +00:00
|
|
|
}
|