Vue-apollo: Call query after mutation

Created on 7 Jun 2017  路  2Comments  路  Source: vuejs/vue-apollo

Hi,

I'm using vue-apollo for the component's data. It works fine and calls the query when the component will be created. But I need to query the data again after mutations. How can I achieve this?

That's the essential part of the component:

export default {
  data() {
    return {
      players: []
    }
  },
  apollo: {
    players: queries.Players
  },
  methods: {
    async deletePlayer(userToDelete) {
      await (this.$apollo.mutate({
        mutation: mutations.DeletePlayer,
        variables: {
          id: userToDelete.id
        }
      }))
      // TODO: call query again
    }
  }
}

Most helpful comment

hey, use update for mutation to update cache: http://dev.apollodata.com/react/cache-updates.html#directAccess , or refetching all by this.$apollo.queries.QUERY_NAME.refetch(). But best solution is update cache

All 2 comments

hey, use update for mutation to update cache: http://dev.apollodata.com/react/cache-updates.html#directAccess , or refetching all by this.$apollo.queries.QUERY_NAME.refetch(). But best solution is update cache

Thanks for the fast answer.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

beeplin picture beeplin  路  4Comments

igaloly picture igaloly  路  3Comments

dsbert picture dsbert  路  4Comments

ais-one picture ais-one  路  4Comments

danthareja picture danthareja  路  4Comments