Vue-apollo: Can't seem to initialize data

Created on 7 May 2018  路  12Comments  路  Source: vuejs/vue-apollo

  data () {
    return {
      me: {
        name: null
      }
    }
  },

  apollo: {
    me: gql`{
        me {
          name
        }
      }`
  }

name remains null after the query. I can access the data but only with $data.$apolloData.data.me.name which seems like the wrong way.

If I remove the me {} property from data() then I get the following error:

TypeError: Cannot read property 'hasOwnProperty' of undefined
    at _loop (vue-apollo.esm.js?ebd5:3924)
    at VueComponent.launch (vue-apollo.esm.js?ebd5:3938)
    at callHook (vue.runtime.esm.js?ff9b:2917)
    at VueComponent.Vue._init (vue.runtime.esm.js?ff9b:4626)
    at new VueComponent (vue.runtime.esm.js?ff9b:4794)
    at createComponentInstanceForVnode (vue.runtime.esm.js?ff9b:4306)
    at init (vue.runtime.esm.js?ff9b:4127)
    at createComponent (vue.runtime.esm.js?ff9b:5604)
    at createElm (vue.runtime.esm.js?ff9b:5551)
    at VueComponent.patch [as __patch__] (vue.runtime.esm.js?ff9b:6087)

I just started this project with vue-cli 3 and added apollo with vue-cli.
I've disabled subscriptions.

bug

Most helpful comment

Maybe is better to downgrade to beta 5.

This. 馃悎

All 12 comments

This seems to be a regression of the latest version. Will fix it tomorrow. In the meantime, you can remove your data () { ... } option.

Is there a short-term workaround for this issue?

@maziarz

It seems like a simple work around, until the issue is fixed, is to employ the result callback and set your data manually.

export default {
  data () {
    return {
      me: {
        name: null
      }
    }
  },

  apollo: {
    me: {
      query: gql`{
        me {
          name
        }
      }`,
      result({ data, loading, networkStatus }) {
        this.me = data.me
      },

      error(err) {
        // handle your error
      }
    }
  }
}

At least, that's what I did, and it seems to be working so far.

Hope it helps,

~ Ayiga

Thanks @Ayiga, that did the trick :-)

Same issue here, @Akryum can you fix that?

I don't think it's the correct way to use result to pass data in the vm but it's a good way before the fix. Maybe is better to downgrade to beta 5.

Maybe is better to downgrade to beta 5.

This. 馃悎

Using for the first time (through nuxtjs/apollo) been trying to figure it out all day until i came across this.

Downgrading has fixed the issue for now.

@binzcodes same here, as soon as there is a release, the nuxt module should be updated

beta 10 is released already 馃悎

@Akryum excellent! Thanks 馃

great thanks @Akryum 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danthareja picture danthareja  路  4Comments

ais-one picture ais-one  路  4Comments

alx13 picture alx13  路  4Comments

beeplin picture beeplin  路  4Comments

igaloly picture igaloly  路  3Comments