feat: team invitation caching
This commit is contained in:
@@ -9,4 +9,5 @@ export const optimisticDefs: GraphCacheOptimisticUpdaters = {
|
||||
name: newName,
|
||||
}),
|
||||
removeTeamMember: () => true,
|
||||
revokeTeamInvitation: () => true,
|
||||
}
|
||||
|
||||
@@ -10,5 +10,9 @@ export const resolversDef: GraphCacheResolvers = {
|
||||
__typename: "User",
|
||||
uid,
|
||||
}),
|
||||
teamInvitation: (_parent, args, _cache, _info) => ({
|
||||
__typename: "TeamInvitation",
|
||||
id: args.inviteID,
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -68,5 +68,51 @@ export const updatesDef: GraphCacheUpdaters = {
|
||||
|
||||
cache.link({ __typename: "Team", id: teamID }, "members", newMembers)
|
||||
},
|
||||
createTeamInvitation: (result, _args, cache, _info) => {
|
||||
cache.invalidate(
|
||||
{
|
||||
__typename: "Team",
|
||||
id: result.createTeamInvitation.teamID!,
|
||||
},
|
||||
"teamInvitations"
|
||||
)
|
||||
},
|
||||
acceptTeamInvitation: (_result, _args, cache, _info) => {
|
||||
cache.invalidate({ __typename: "Query" }, "myTeams")
|
||||
},
|
||||
revokeTeamInvitation: (_result, args, cache, _info) => {
|
||||
const targetTeamID = cache.resolve(
|
||||
{
|
||||
__typename: "TeamInvitation",
|
||||
id: args.inviteID,
|
||||
},
|
||||
"teamID"
|
||||
)
|
||||
|
||||
if (typeof targetTeamID === "string") {
|
||||
const newInvites = (
|
||||
cache.resolve(
|
||||
{
|
||||
__typename: "Team",
|
||||
id: targetTeamID,
|
||||
},
|
||||
"teamInvitations"
|
||||
) as string[]
|
||||
).filter(
|
||||
(inviteKey) =>
|
||||
inviteKey !==
|
||||
cache.keyOfEntity({
|
||||
__typename: "TeamInvitation",
|
||||
id: args.inviteID,
|
||||
})
|
||||
)
|
||||
|
||||
cache.link(
|
||||
{ __typename: "Team", id: targetTeamID },
|
||||
"teamInvitations",
|
||||
newInvites
|
||||
)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user