Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

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

Open
frederikhors opened this issue Jan 31, 2020 · 0 comments

Comments

@frederikhors
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant