apollographql/apollo-link

SPA, check current pending fetch requests with fetch API or event or without Apollo

Opened this issue · 0 comments

Coming from jQuery I know I can use jQuery.active to check the number of active jQuery AJAX connections; I have to constantly poll that var in order to have an event fired in the advent of a new connection. I can also use jQuery.ajaxStart() and jQuery.ajaxStop() events.

Apollo Link (https://github.com/apollographql/apollo-link) is the layer which effectively starts GET/POST requests.

Is there any way to verify that requests are pending?

Here a user tried it: apollographql/apollo-link-state#236 using this code:

const queryInProcessNotifier = new ApolloLink((operation, forward) => {
  client.mutate({mutation:M_CHANGE_APP_SETTING, variables: { setting:"appIsLoading", state:true }})
  return forward(operation).map((data) => {
    client.mutate({mutation:M_CHANGE_APP_SETTING, variables: { setting:"appIsLoading", state:false }})
    return data
  })
})

It works because every request passes through there, but if it were to be interrupted for any reason my status would no longer change to false.

Also I have many parallel requests to check, so I can create a "counter" +1 / -1 for each request, but still the problem with the interrupted ones.

What do you think about?

Is there a way without libraries at all?

Is there a fetch API or event to subscribe?