React-apollo: Reset cache by especific query or mutation

Created on 23 Jul 2018  路  3Comments  路  Source: apollographql/react-apollo

Hi!
I want to use the client of react-apollo to reset part of the cache from a key or query, not clean the entirely cache using the client.resetStore().

Example:

import { withApollo } from "react-apollo";
import { compose } from "recompose";
import MyComponent from "./MyComponent";

const cleanEspecificCache = ({ client }) => () =>{
  // What i do here?
}

const enhance = compose(
 withApollo,
 withHandlers({cleanEspecificCache})
)

export default enhance(MyComponent);

What i do to make it works? Thanks!

All 3 comments

I filed a feature request for what looks like your need: https://github.com/apollographql/apollo-feature-requests/issues/29 please upvote

Use writeQuery or writeData depending on your needs.

A simple way to reset the cache for a specific query is to call the query again with fetchPolicy: 'network-only'. GraphQL fetches data from API and updates the cache after results are received.

Was this page helpful?
0 / 5 - 0 ratings