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

Error: No such model #156

Closed
t2thec opened this issue Aug 12, 2020 · 1 comment
Closed

Error: No such model #156

t2thec opened this issue Aug 12, 2020 · 1 comment

Comments

@t2thec
Copy link

t2thec commented Aug 12, 2020

Hi, thanks for the awesome package.

I can't seem to fetch a model. I keep getting 'No such model' error. However, I think I have things set up OK.

Is this package Vue3/Vuex4 compatible? Can you see where I have screwed up?

Thanks in advance!

"@vuex-orm/core": "^0.36.3",
"@vuex-orm/plugin-graphql": "^1.0.0-rc.41",

"vue": "^3.0.0-rc.5",
"vuex": "^4.0.0-beta.4"

database.js

import { Database, use } from '@vuex-orm/core'
import VuexORMGraphQL from '@vuex-orm/plugin-graphql'
import User from '@/models/User/User'

export const database = new Database()

use(VuexORMGraphQL, {
  database,
  url:
    process.env.NODE_ENV !== 'production'
      ? 'http://domain.test/graphql'
      : null,
  connectionQueryMode: 'plain',
  debug: process.env.NODE_ENV !== 'production',
})

database.register(User)

store.js

import { createStore } from 'vuex'
import { install } from '@vuex-orm/core'
import { database } from './database'

export default createStore({
  plugins: [install(database)],
})

HelloWorld.vue

<script>
  import User from '@/models/User/User'
  // import { useStore } from 'vuex'

  export default {
    name: 'HelloWorld',
    props: {
      msg: String,
    },
    async setup() {
      await User.fetch() // errors
      console.log(User.all()) // Returns []
    },
  }
</script>

User.js

import { Model } from '@vuex-orm/core'

export default class User extends Model {
  static entity = 'users'

  static fields() {
    return {
      id: this.number(null),
      /******/
  }
}

Error:

Uncaught (in promise) Error: No such model user!
    at Context.getModel (vuex-orm-graphql.esm.js?410d:14923)
    at Function.getModelFromState (vuex-orm-graphql.esm.js?410d:15384)
    at Function.call (vuex-orm-graphql.esm.js?410d:15504)
    at Array.wrappedActionHandler (vuex.esm-browser.js?5502:809)
    at Store.dispatch (vuex.esm-browser.js?5502:484)
    at Store.boundDispatch [as dispatch] (vuex.esm-browser.js?5502:369)
    at Function.Model.dispatch (vuex-orm.esm.js?0937:2689)
    at Function.model.fetch (vuex-orm-graphql.esm.js?410d:15493)
    at _callee$ (HelloWorld.vue?fdab:110)
    at tryCatch (runtime.js?96cf:62)
@t2thec t2thec changed the title No such model Error: No such model Aug 12, 2020
@t2thec
Copy link
Author

t2thec commented Aug 13, 2020

Ahh, I found the answer to this. In my database.js file, I needed to register my models before setting up. So I have gone from what is above to...

import { Database, use } from '@vuex-orm/core'
import VuexORMGraphQL from '@vuex-orm/plugin-graphql'
import User from '@/models/User/User'

export const database = new Database()

database.register(User) // Moved the registration above the block below - D'oh!

use(VuexORMGraphQL, {
  database,
  url:
    process.env.NODE_ENV !== 'production'
      ? 'http://domain.test/graphql'
      : null,
  connectionQueryMode: 'plain',
  debug: process.env.NODE_ENV !== 'production',
})

@t2thec t2thec closed this as completed Aug 13, 2020
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

1 participant