ソースを参照

feat: team invitation caching

Andrew Bastin 4 年 前
コミット
f0a6fc641a

+ 1 - 0
packages/hoppscotch-app/helpers/backend/caching/optimistic.ts

@@ -9,4 +9,5 @@ export const optimisticDefs: GraphCacheOptimisticUpdaters = {
     name: newName,
   }),
   removeTeamMember: () => true,
+  revokeTeamInvitation: () => true,
 }

+ 4 - 0
packages/hoppscotch-app/helpers/backend/caching/resolvers.ts

@@ -10,5 +10,9 @@ export const resolversDef: GraphCacheResolvers = {
       __typename: "User",
       uid,
     }),
+    teamInvitation: (_parent, args, _cache, _info) => ({
+      __typename: "TeamInvitation",
+      id: args.inviteID,
+    }),
   },
 }

+ 46 - 0
packages/hoppscotch-app/helpers/backend/caching/updates.ts

@@ -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
+        )
+      }
+    },
   },
 }