Skip to content

Commit

Permalink
PREAPPS-6634: Update InMemoryCache typePolicies for search result cac…
Browse files Browse the repository at this point in the history
…hing
  • Loading branch information
lavegupta committed Apr 14, 2022
1 parent 534798a commit 2dfea9f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/apollo/zimbra-in-memory-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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'])
}
}
},
Expand Down

0 comments on commit 2dfea9f

Please sign in to comment.