mirror of
https://github.com/unraid/api.git
synced 2026-02-27 12:18:41 -06:00
refactor(web): reduce magic in identifying apollo cache item
This commit is contained in:
@@ -2,4 +2,5 @@
|
||||
* The magic 'Notification' prefix comes from inspecting the apollo cache.
|
||||
* I think it comes from the __typename when apollo caches an object (by default)
|
||||
*/
|
||||
export const NOTIFICATION_CACHE_PREFIX = "Notification";
|
||||
export const NotificationType = "Notification";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { InMemoryCache, type InMemoryCacheConfig } from "@apollo/client/core";
|
||||
import { mergeAndDedup } from "./merge";
|
||||
import { NOTIFICATION_CACHE_PREFIX } from "./prefixes";
|
||||
import { NotificationType } from "../../composables/gql/typename";
|
||||
|
||||
/**------------------------------------------------------------------------
|
||||
* ! Understanding Cache Type Policies
|
||||
@@ -90,7 +90,11 @@ const defaultCacheConfig: InMemoryCacheConfig = {
|
||||
*/
|
||||
merge(_, incoming, { cache, args }) {
|
||||
if (args?.id) {
|
||||
cache.evict({ id: `${NOTIFICATION_CACHE_PREFIX}:${args.id}` });
|
||||
const id = cache.identify({
|
||||
id: args.id,
|
||||
__typename: NotificationType,
|
||||
});
|
||||
cache.evict({ id });
|
||||
}
|
||||
// Removes references to evicted notification, preventing dangling references
|
||||
cache.gc();
|
||||
|
||||
Reference in New Issue
Block a user