简体   繁体   中英

How to pass multiple queries into refetchQueries in apollo/graphql

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 });
 });

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM