Reputation: 5987
I have a mutation named deleteSong
. I was wondering after the mutation has passed through how can I pass multiple queries into refetchQueries
?
this.props
.deleteSong({
variables: { id },
refetchQueries: [{ query: fetchSongs }] //<-- I only know how to pass 1 query
})
.then(() => {})
.catch(err => {
this.setState({ err });
});
Upvotes: 5
Views: 5276
Reputation: 15898
The Apollo Client documentation says the following about refetchQueries: A function that allows you to specify which queries you want to refetch after a mutation has occurred. So it should be possible for you to pass either a single or multiple queries to refetchQueries()
.
Basically it should be:
this.props
.deleteSong({
variables: { id },
refetchQueries: [{ query: FETCH_SONGS }, { query: FETCH_FOLLOWERS }]
})
.then(() => {})
.catch(err => {
this.setState({ err });
});
Whereas FETCH_SONG
and FETCH_FOLLOWERS
should be defined by graphql-tag. Maybe let others know if this solution works for you.
Upvotes: 7