-
Describe the bug But in global component, my spinner never shows with $apollo.loading. I want my spinner in the top right corner showing when there are any queries to graphql server. Is this a bug or I missed some configuration? Versions |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
This issue has been present in apollo for almost 3 years now. See #1314 |
Beta Was this translation helpful? Give feedback.
-
I am still seeing this issue. |
Beta Was this translation helpful? Give feedback.
-
Jep. Same here. |
Beta Was this translation helpful? Give feedback.
-
Did anyone figure out a solution for this? |
Beta Was this translation helpful? Give feedback.
-
This is expected behavior: const apolloProvider = new VueApollo({
// Watch loading state for all queries
// See 'Smart Query > options > watchLoading' for detail
watchLoading (isLoading, countModifier) {
loading += countModifier
console.log('Global loading', loading, countModifier)
},
}) |
Beta Was this translation helpful? Give feedback.
-
@Akryum thanks so much for clarifying. I've got the loading indicator logged in the console now. What i can't work out now from the docs is how to access that loading state in any template? |
Beta Was this translation helpful? Give feedback.
-
The implementation is left to you. You can for example use const apolloState = Vue.observable({
loading: 0,
})
Vue.mixin({
computed: {
$apolloGlobalLoading () { return apolloState.loading > 0 }
}
})
const apolloProvider = new VueApollo({
// Watch loading state for all queries
// See 'Smart Query > options > watchLoading' for detail
watchLoading (isLoading, countModifier) {
apolloState.loading += countModifier
console.log('Global loading', loading, countModifier)
},
}) <template>
<div v-if="$apolloGlobalLoading">Loading some query...</div>
</template> |
Beta Was this translation helpful? Give feedback.
-
Fantastic that worked @Akryum . Then in nuxt.config.js: modules: [
'@nuxtjs/apollo',
'@nuxtjs/observable'
],
apollo: {
includeNodeModules: true,
watchLoading: '@/apollo/loadingHandler.js'
}, @/apollo/loadingHandler.js: export default (isLoading, countModifier, nuxtContext) => {
isLoading += countModifier
nuxtContext.$state.loading += countModifier;
} /state.js export default() => ({
loading: 0,
}) then in your templates you can use <loading-icon :is-loading="$state.loading"></loading-icon> |
Beta Was this translation helpful? Give feedback.
The implementation is left to you. You can for example use
Vue.observable()
to create a small reactive object that you can import in your components or in a global mixin.