apollo: $apollo undefined in context.app
If i try to use apollo in fetch or asyncData, $apollo is not defined in context.app:
async fetch ({ app, store }) {
const { data } = await app.$apollo.query({
query: gql`query { posts: { id } }`
})
}
For now I use this work around but I’m just curious why $apollo isn’t defined.
async fetch ({ app, store }) {
const { data } = await app.apolloProvider.defaultClient.query({
query: gql`query { posts: { id } }`
})
}
<div align="right">This question is available on Nuxt.js community (#c10)</div>About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (4 by maintainers)
I am using
const client = this.app.apolloProvider.defaultClientin my store/index.js file and I’m getting undefined error. it seems this.app doesn’t contain apolloProvider. anyone facing the same issue?Not really. The nice thing about the fetch method is that you get the loading indicator for free and you are guaranteed that the data is 100% loaded.
If someone will be looking for an answer here like I did, in Vuex store you have to get client like this
const client = this.app.provide.$apolloProvider.defaultClientHere is how i did for now :