File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 11import { InMemoryCache , type InMemoryCacheConfig } from '@apollo/client/core/index.js' ;
2+ import type { NotificationOverview } from '~/composables/gql/graphql' ;
23import { NotificationType } from '../../composables/gql/typename' ;
34import { mergeAndDedup } from './merge' ;
45
@@ -56,6 +57,34 @@ const defaultCacheConfig: InMemoryCacheConfig = {
5657 } ) ;
5758 } ,
5859 } ,
60+ overview : {
61+ /**
62+ * Busts notification cache when new unread notifications are detected.
63+ *
64+ * This allows incoming notifications to appear in the sidebar without reloading the page.
65+ *
66+ * @param existing - Existing overview data in cache
67+ * @param incoming - New overview data from server
68+ * @param context - Apollo context containing cache instance
69+ * @returns The overview data to be cached
70+ */
71+ merge (
72+ existing : Partial < NotificationOverview > | undefined ,
73+ incoming : Partial < NotificationOverview > | undefined ,
74+ { cache }
75+ ) {
76+ const hasNewUnreads =
77+ isDefined ( existing ?. unread ?. total ) &&
78+ isDefined ( incoming ?. unread ?. total ) &&
79+ existing . unread . total < incoming . unread . total ;
80+
81+ if ( hasNewUnreads ) {
82+ cache . evict ( { fieldName : 'notifications' } ) ;
83+ cache . gc ( ) ;
84+ }
85+ return incoming ;
86+ } ,
87+ } ,
5988 } ,
6089 } ,
6190 Mutation : {
You can’t perform that action at this time.
0 commit comments