apollo icon indicating copy to clipboard operation
apollo copied to clipboard

Global watch loading not working.

Open kicaal opened this issue 5 years ago • 4 comments

It never passes through the function that I have defined, is it necessary to put a specific parameter? any ideas?

Configuration:

 apollo: {
    errorHandler: '~/plugins/apollo-error-handler.js',
    watchLoading: '~/plugins/apollo-watch-loading-handler.js',
    clientConfigs: {
      default: '~/apollo/client-configs/default.js',
    },
    defaultOptions: {
      // See 'apollo' definition
      // For example: default query options
      $query: {
        loadingKey: 'loading',
        fetchPolicy: 'no-cache',
      },
    },
  },

watchLoading: '~/plugins/apollo-watch-loading-handler.js',

export default (isLoading, countModifier, nuxtContext) => {
  console.log(nuxtContext)
  console.log('Global loading', isLoading, countModifier)
}

kicaal avatar May 15 '20 09:05 kicaal

I have the same problem.

It seems to pass through the function only if you use apollo server-side e.g. with a smart query.

My '~/plugins/apollo.loading.js'

export default (isLoading, countModifier, nuxtContext) => {
  // eslint-disable-next-line
  console.log(process.server, process.client, isLoading, 'LOADING PLUGIN')
}

this prints:

true false true LOADING PLUGIN                                                                                                                                      
true false true LOADING PLUGIN (repeated 0 times)                                                                                                                   
true false false LOADING PLUGIN                                                                                                                                     
true false false LOADING PLUGIN (repeated 0 times)                                                                                                                  
true false true LOADING PLUGIN                                                                                                                                      
true false false LOADING PLUGIN  

and these are the cals I make server-side in my app. Client-side calls don't go throught the plugin.

YannisMarios avatar May 17 '20 07:05 YannisMarios

so how to watch loading in client side?

ZhangGangTW avatar May 23 '20 15:05 ZhangGangTW

maybe with a middleware that runs in all pages? it should work

xavism avatar Oct 29 '20 19:10 xavism

If anyone is interested, I managed to get the Apollo global loading observer working after a bit of guidance from this thread. I posted my solution here.

toddpadwick avatar Nov 29 '21 16:11 toddpadwick