Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to this.$apollo from Vuex store with vue-apollo in NUXT?

I want to store the user that comes from the login on an action in the vuex store. But there is no access to this.$apollo.

export const actions = {
  UPSERT_USER({ commit }, { authUser, claims }) {
     this.$apollo
        .mutate({
          mutation: UPSERT_USER_MUTATION,
          variables: {
            id: user.uid,
            email: user.email,
            name: user.name,
            picture: user.picture,
          },
        })
    }

Thanks!

like image 904
ctwhome Avatar asked Jan 25 '23 01:01

ctwhome


2 Answers

You should be able to access it like this:

export default {
  actions: {
    foo (store, payload) {
      let client = this.app.apolloProvider.defaultClient
    }
  }
}

Check out the https://github.com/nuxt-community/apollo-module

like image 170
ajobi Avatar answered Feb 24 '23 18:02

ajobi


Because I inject apolloProvider in my nuxt apollo plugin using,

inject("apollo", apolloProvider);

Then in my case I access it using,

export default {
  actions: {
    foo (store, payload) {
        let apolloClient = this.$apollo.defaultClient
    }
  }
}
like image 39
Endriyas Avatar answered Feb 24 '23 17:02

Endriyas