Skip to content

Instantly share code, notes, and snippets.

Last active March 23, 2021 16:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lydemann/0ebcbf52cafc5dca64c301bdce462468 to your computer and use it in GitHub Desktop.
export function removeFromCache<ReadQueryResponseT>(
toRemove: EntityObject,
readQuery: DocumentNode,
cache: ApolloCache<any>,
entityName: keyof ReadQueryResponseT
) {
const existingEntities = cache.readQuery<
Record<keyof ReadQueryResponseT, EntityObject[]>
query: readQuery,
if (toRemove && existingEntities) {
query: readQuery,
data: {
[entityName]: existingEntities[entityName].filter(
(entity) => !==
cache.evict({ id: })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment