vuex-orm / plugin-graphql

Vuex ORM persistence plugin to sync the store against a GraphQL API.
https://vuex-orm.github.io/plugin-graphql/
MIT License
227 stars 52 forks source link

Trouble with fetch() in Nuxt app #166

Closed jimmiejackson414-zz closed 3 years ago

jimmiejackson414-zz commented 3 years ago

I hate having to post questions in Issues, but I'm having trouble getting this to work. I've been a huge fan of the @vuex-orm system for awhile, and would love to get this rolling on a new GraphQL project. I asked this question on StackOverflow and the Slack channel but never received an answer.

You can take a look at the Stack link for detailed code, but essentially I am receiving the error [vuex] unknown action type: entities/notifications/fetch when trying to run Notification.fetch() in the mounted lifecycle of a component. Do you have any suggestions?

jimmiejackson414-zz commented 3 years ago

So in a Hail Mary throw to get this working, I ended up making a couple of changes that actually worked!

If other people come across this having similar issues, here's what I did... In my nuxt.config.js, swapped the order of the two plugins to this:

plugins: [
    '~/plugins/graphql',
    '~/plugins/vuex-orm',
],

In my graphql.js plugin, I rearranged the order of the options to this (database first, followed by adapter):

  const options = {
    database,
    adapter: new CustomAdapter(),
    url: env.NUXT_ENV_BACKEND_API_URL,
    debug: process.env.NODE_ENV !== 'production'
  };