mobilizon.chapril.org-mobil.../js/src/apollo/user.ts

56 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-08-12 16:04:16 +02:00
import { ApolloCache } from 'apollo-cache';
import { NormalizedCacheObject } from 'apollo-cache-inmemory';
import { ICurrentUserRole } from '@/types/current-user.model';
2019-08-12 16:04:16 +02:00
export function buildCurrentUserResolver(cache: ApolloCache<NormalizedCacheObject>) {
cache.writeData({
data: {
currentUser: {
__typename: 'CurrentUser',
id: null,
email: null,
isLoggedIn: false,
role: ICurrentUserRole.USER,
2019-08-12 16:04:16 +02:00
},
currentActor: {
__typename: 'CurrentActor',
id: null,
preferredUsername: null,
name: null,
avatar: null,
},
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 {
2019-08-21 11:25:09 +02:00
Mutation: {
updateCurrentUser: (_, { id, email, isLoggedIn, role }, { cache }) => {
2019-08-21 11:25:09 +02:00
const data = {
2019-01-18 14:47:10 +01:00
currentUser: {
id,
email,
isLoggedIn,
role,
2019-01-18 14:47:10 +01:00
__typename: 'CurrentUser',
},
2019-08-21 11:25:09 +02:00
};
2019-01-18 14:47:10 +01:00
cache.writeData({ data });
},
updateCurrentActor: (_, { id, preferredUsername, avatar, name }, { cache }) => {
const data = {
currentActor: {
id,
preferredUsername,
avatar,
name,
__typename: 'CurrentActor',
},
};
2019-08-21 11:25:09 +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
}