I am using apollo graphql in my react application. Say I have the following query:
query ListQuery($filter: String!) {
items(filter: $filter) {
id
n
Try this:
query ListQuery($filter: String!) {
items(filter: $filter) {
id
name
}
},
fetchPolicy: 'no-cache'
More here: https://www.apollographql.com/docs/react/caching/cache-interaction/#bypassing-the-cache
Read about fetch policies options.fetchPolicy
--Edit:--
But it is only as a trick if you want reset only one query. To reset all store see answer by @Nitin : Set fetchPolicy to network-only. Refresh query. Return it to option of your choice.
In your case, you can use the apollo's method client.resetStore();
It will clear the previous cache and then load the active queries.
Seems like what you need is refetchQueries option/prop to be set to array of query names strings. The documentation states that:
If options.refetchQueries is an array of strings then Apollo Client will look for any queries with the same names as the provided strings and will refetch those queries with their current variables.
So as an example for using graphql
HOC you could try to do:
function SomeComponent(props) {
const performMutation = () => {
props.doStuff({ refetchQueries: ["ListQuery"] })
.then(/* ... */)
.catch(/* ... */)
}
return (/* ... */)
}
export default graphql(DO_STUFF, { name: "doStuff" })(SomeComponent)
Or with the Mutation
component:
function SomeComponent(props) {
return (
<Mutation
mutation={DO_STUFF}
refetchQueries={mutationResult => ["ListQuery"]}>
{(doStuff, { loading, error }) => {
/* ... */
}}
</Mutation>
);
}
If this is somehow doesn't do what you need, there is also a workaround using update option.
Hope this helps.