From 1da882b80752aac3a4b6f104f642eaa6ffac40d4 Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Tue, 29 Oct 2024 11:31:29 -0400 Subject: [PATCH] refactor(web): extract notification object cache prefix to a constant --- web/helpers/apollo-cache/index.ts | 5 ++--- web/helpers/apollo-cache/prefixes.ts | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 web/helpers/apollo-cache/prefixes.ts diff --git a/web/helpers/apollo-cache/index.ts b/web/helpers/apollo-cache/index.ts index bf1273e27..8b780cbc5 100644 --- a/web/helpers/apollo-cache/index.ts +++ b/web/helpers/apollo-cache/index.ts @@ -1,5 +1,6 @@ import { InMemoryCache, type InMemoryCacheConfig } from "@apollo/client/core"; import { mergeAndDedup } from "./merge"; +import { NOTIFICATION_CACHE_PREFIX } from "./prefixes"; /**------------------------------------------------------------------------ * ! Understanding Cache Type Policies @@ -89,9 +90,7 @@ const defaultCacheConfig: InMemoryCacheConfig = { */ merge(_, incoming, { cache, args }) { if (args?.id) { - // The magic 'Notification:' prefix comes from inspecting the apollo cache - // I think it comes from the __typename when apollo caches an object (by default) - cache.evict({ id: `Notification:${args.id}` }); + cache.evict({ id: `${NOTIFICATION_CACHE_PREFIX}:${args.id}` }); } // Removes references to evicted notification, preventing dangling references cache.gc(); diff --git a/web/helpers/apollo-cache/prefixes.ts b/web/helpers/apollo-cache/prefixes.ts new file mode 100644 index 000000000..a5964dce1 --- /dev/null +++ b/web/helpers/apollo-cache/prefixes.ts @@ -0,0 +1,5 @@ +/** + * The magic 'Notification' prefix comes from inspecting the apollo cachel. + * I think it comes from the __typename when apollo caches an object (by default) + */ +export const NOTIFICATION_CACHE_PREFIX = "Notification";