Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using apollo-module with NuxtJS inside a vuex Action #220

Closed
Pixselve opened this issue Jan 19, 2020 · 1 comment
Closed

Using apollo-module with NuxtJS inside a vuex Action #220

Pixselve opened this issue Jan 19, 2020 · 1 comment

Comments

@Pixselve
Copy link

Hello,

I am trying to refactor my store using vuex-module-decorators but I am facing an issue with the apollo-module of NuxtJS.
In the old store, we would use this :

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

So I have done that in my code

  @Action({ commit: 'update' })
  async fetchTeacher() {
    // @ts-ignore
    let client = this.app.apolloProvider.defaultClient;
    const { data }: { data: MeTeacherQuery } = await client.query({
      query: MeTeacherQueryGQL
    });

    return data.meTeacher;
  }

But now, I have this error

 ERROR  ERR_ACTION_ACCESS_UNDEFINED: Are you trying to access this.someMutation() or this.someGetter inside an @Action?                                                                                                                                                                                                                               16:34:03
That works only in dynamic modules.
If not dynamic use this.context.commit("mutationName", payload) and this.context.getters["getterName"]
Error: Could not perform action fetchTeacher
    at Store.<anonymous> (vuex-module-decorators\src\action.ts:55:17)
    at step (\vuex-module-decorators\dist\cjs\index.js:132:23)
    at Object.throw (vuex-module-decorators\dist\cjs\index.js:113:53)
    at rejected (vuex-module-decorators\dist\cjs\index.js:104:65)
TypeError: Cannot read property 'apolloProvider' of undefined
    at Object.fetchTeacher (server.js:6339:27)
    at Store.<anonymous> (vuex-module-decorators\src\action.ts:34:48)
    at step (vuex-module-decorators\dist\cjs\index.js:132:23)
    at Object.next (vuex-module-decorators\dist\cjs\index.js:113:53)
    at vuex-module-decorators\dist\cjs\index.js:106:71
    at new Promise (<anonymous>)
    at __awaiter (vuex-module-decorators\dist\cjs\index.js:102:12)
    at Store.action (vuex-module-decorators\dist\cjs\index.js:323:20)
    at Array.wrappedActionHandler (vuex\dist\vuex.common.js:734:23)
    at Store.dispatch (vuex\dist\vuex.common.js:439:15)
@JasonLandbridge
Copy link

Is your store module dynamic: true?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants