2020-11-27 19:27:44 +01:00
|
|
|
import { ICurrentUserRole } from "@/types/enums";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { ApolloCache } from "apollo-cache";
|
|
|
|
import { NormalizedCacheObject } from "apollo-cache-inmemory";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { Resolvers } from "apollo-client/core/types";
|
2019-08-12 16:04:16 +02:00
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
export default function buildCurrentUserResolver(
|
|
|
|
cache: ApolloCache<NormalizedCacheObject>
|
|
|
|
): Resolvers {
|
2019-08-12 16:04:16 +02:00
|
|
|
cache.writeData({
|
|
|
|
data: {
|
|
|
|
currentUser: {
|
2020-02-18 08:57:00 +01:00
|
|
|
__typename: "CurrentUser",
|
2019-08-12 16:04:16 +02:00
|
|
|
id: null,
|
|
|
|
email: null,
|
|
|
|
isLoggedIn: false,
|
2019-09-09 09:31:08 +02:00
|
|
|
role: ICurrentUserRole.USER,
|
2019-08-12 16:04:16 +02:00
|
|
|
},
|
2019-09-11 09:59:01 +02:00
|
|
|
currentActor: {
|
2020-02-18 08:57:00 +01:00
|
|
|
__typename: "CurrentActor",
|
2019-09-11 09:59:01 +02:00
|
|
|
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: {
|
2020-02-18 08:57:00 +01:00
|
|
|
updateCurrentUser: (
|
|
|
|
_: any,
|
|
|
|
{
|
|
|
|
id,
|
|
|
|
email,
|
|
|
|
isLoggedIn,
|
|
|
|
role,
|
|
|
|
}: { id: string; email: string; isLoggedIn: boolean; role: string },
|
|
|
|
{ cache: localCache }: { cache: ApolloCache<NormalizedCacheObject> }
|
|
|
|
) => {
|
2019-08-21 11:25:09 +02:00
|
|
|
const data = {
|
2019-01-18 14:47:10 +01:00
|
|
|
currentUser: {
|
|
|
|
id,
|
|
|
|
email,
|
2019-04-01 11:49:54 +02:00
|
|
|
isLoggedIn,
|
2019-09-09 09:31:08 +02:00
|
|
|
role,
|
2020-02-18 08:57:00 +01:00
|
|
|
__typename: "CurrentUser",
|
2019-01-18 14:47:10 +01:00
|
|
|
},
|
2019-08-21 11:25:09 +02:00
|
|
|
};
|
2019-01-18 14:47:10 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
localCache.writeData({ data });
|
2019-09-11 09:59:01 +02:00
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
updateCurrentActor: (
|
|
|
|
_: any,
|
|
|
|
{
|
|
|
|
id,
|
|
|
|
preferredUsername,
|
|
|
|
avatar,
|
|
|
|
name,
|
|
|
|
}: { id: string; preferredUsername: string; avatar: string; name: string },
|
|
|
|
{ cache: localCache }: { cache: ApolloCache<NormalizedCacheObject> }
|
|
|
|
) => {
|
2019-09-11 09:59:01 +02:00
|
|
|
const data = {
|
|
|
|
currentActor: {
|
|
|
|
id,
|
|
|
|
preferredUsername,
|
|
|
|
avatar,
|
|
|
|
name,
|
2020-02-18 08:57:00 +01:00
|
|
|
__typename: "CurrentActor",
|
2019-09-11 09:59:01 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
localCache.writeData({ data });
|
2019-08-21 11:25:09 +02:00
|
|
|
},
|
2019-01-18 14:47:10 +01:00
|
|
|
},
|
2019-08-12 16:04:16 +02:00
|
|
|
};
|
2019-08-13 08:43:37 +02:00
|
|
|
}
|