Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow stopPolling to abort in flight queries. #347

Open
jsamr opened this issue Oct 11, 2022 · 0 comments
Open

Allow stopPolling to abort in flight queries. #347

jsamr opened this issue Oct 11, 2022 · 0 comments
Labels
core Feature requests related to core functionality

Comments

@jsamr
Copy link

jsamr commented Oct 11, 2022

Why

I'm running in an issue involving polling with cache writes. Let's say I have a network request on Q which returns a collection of type A. This type A is joined with a collection of type B.

type A = {
  id: string;
  bList: B[];
}

A is being polled every 5 seconds. I have a mutation M which creates new instances of B. In the context of a React app, I use the update function of parameters for mutation M to write to the cache of query Q with cache.updateQuery, and append created items of type B to instances of type A.

Because I don't want polling to occur while mutation M is ongoing, I stopPolling right before initiating M. However, since stopPolling doesn't abort in flight queries, it will sometimes happen that Q cache writes are overridden by a query Q initiated before polling was stopped, causing UI inconsistencies.

Proposed solution

  • Add an abortInFlightQueries flag to stopPolling function;
  • Add the ability to configure abortInFlightQueriesWhenPollingStops in useXQuery hook.
const { data, loading, stopPolling } = useXQuery({
  fetchPolicy: "cache-and-network",
  pollInterval: 3000,
  abortInFlightQueriesWhenPollingStops: true,
  variables: { /* ... */ }
});

// ...

stopPolling({ abortInFlightQueries: true });

Related Feature Requests

@jerelmiller jerelmiller added the project-apollo-client (legacy) LEGACY TAG DO NOT USE label Oct 11, 2022
@jerelmiller jerelmiller added the core Feature requests related to core functionality label Apr 6, 2023
@jerelmiller jerelmiller removed the project-apollo-client (legacy) LEGACY TAG DO NOT USE label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Feature requests related to core functionality
Projects
None yet
Development

No branches or pull requests

2 participants