import { DataProxy } from '@apollo/client' ; import { DocumentNode } from 'graphql' ; type UpdateCacheFn < T > = ( cache : T ) => T ; export function updateApolloCache < T > ( client , document , update , variables ? ) { let queryArgs ; if ( variables ) { queryArgs = { query : document , variables , } ; } else { queryArgs = { query : document , } ; } const cache = client . readQuery ( queryArgs ) ; if ( cache ) { const newCache = update ( cache ) ; client . writeQuery ( { ... queryArgs , data : newCache , } ) ; } } export default updateApolloCache ;