diff --git a/src/apollo/zimbra-in-memory-cache.ts b/src/apollo/zimbra-in-memory-cache.ts index b6732842..309fb449 100644 --- a/src/apollo/zimbra-in-memory-cache.ts +++ b/src/apollo/zimbra-in-memory-cache.ts @@ -8,6 +8,16 @@ const dataIdFromPath = (result: any, path: string) => { } }; +const mergeSearches = (existing: any = {}, incoming: any = {}, types: any) => { + const obj: any = { ...incoming }; + + types.forEach((type: string) => { + obj[type] = [...(existing[type] || []), ...(incoming[type] || [])]; + }); + + return obj; +}; + const dataIdFromObject = (object: any) => { switch (object.__typename) { case 'CalendarItemHitInfo': @@ -62,6 +72,11 @@ const typePolicies = { }, getPreferences: { merge: true + }, + search: { + keyArgs: ['types', 'query', 'sortBy'], + merge: (existing: any, incoming: any) => + mergeSearches(existing, incoming, ['contacts', 'messages', 'conversations']) } } },