Skip to content

Commit 65c4fd7

Browse files
committed
refactor(web): reduce magic in identifying apollo cache item
1 parent 9f5a7f8 commit 65c4fd7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

web/helpers/apollo-cache/prefixes.ts renamed to web/composables/gql/typename.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
* The magic 'Notification' prefix comes from inspecting the apollo cache.
33
* I think it comes from the __typename when apollo caches an object (by default)
44
*/
5-
export const NOTIFICATION_CACHE_PREFIX = "Notification";
5+
export const NotificationType = "Notification";
6+

web/helpers/apollo-cache/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { InMemoryCache, type InMemoryCacheConfig } from "@apollo/client/core";
22
import { mergeAndDedup } from "./merge";
3-
import { NOTIFICATION_CACHE_PREFIX } from "./prefixes";
3+
import { NotificationType } from "../../composables/gql/typename";
44

55
/**------------------------------------------------------------------------
66
* ! Understanding Cache Type Policies
@@ -90,7 +90,11 @@ const defaultCacheConfig: InMemoryCacheConfig = {
9090
*/
9191
merge(_, incoming, { cache, args }) {
9292
if (args?.id) {
93-
cache.evict({ id: `${NOTIFICATION_CACHE_PREFIX}:${args.id}` });
93+
const id = cache.identify({
94+
id: args.id,
95+
__typename: NotificationType,
96+
});
97+
cache.evict({ id });
9498
}
9599
// Removes references to evicted notification, preventing dangling references
96100
cache.gc();

0 commit comments

Comments
 (0)