-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): ensure proper cache-removal of deleted note
- Loading branch information
1 parent
c68a6c0
commit 4cabfb9
Showing
2 changed files
with
14 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
import { ApolloCache } from '@apollo/client'; | ||
import apolloClient, { cachePersistor } from '../apollo'; | ||
|
||
export const clearApolloCache = () => { | ||
apolloClient.clearStore(); | ||
cachePersistor.purge(); | ||
}; | ||
|
||
export const removeNoteFromCache = ( | ||
cache: ApolloCache<any>, | ||
note: { _id: string; __typename: string } | ||
): void => { | ||
const normalizedId = cache.identify(note); | ||
cache.evict({ id: normalizedId }); | ||
cache.gc(); // https://stackoverflow.com/questions/63192774/apollo-client-delete-item-from-cache#comment121727251_66713628 | ||
return; | ||
}; |