Skip to content

Commit

Permalink
Merge pull request #4359 from apollographql/stop-QueryManager-more-th…
Browse files Browse the repository at this point in the history
…oroughly

Prevent unhandled rejections by stopping QueryManager more thoroughly.
  • Loading branch information
benjamn authored Jan 22, 2019
2 parents f94cd30 + b3961b9 commit b37ef99
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/apollo-client/src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export class QueryManager<TStore> {
*/
public stop() {
this.scheduler.stop();

this.queries.forEach((_info, queryId) => {
this.stopQueryNoBroadcast(queryId);
});

this.fetchQueryRejectFns.forEach(reject => {
reject(new Error('QueryManager stopped while query was in flight'));
});
Expand Down Expand Up @@ -721,9 +726,14 @@ export class QueryManager<TStore> {
}

public stopQueryInStore(queryId: string) {
this.stopQueryInStoreNoBroadcast(queryId);
this.broadcastQueries();
}

private stopQueryInStoreNoBroadcast(queryId: string) {
this.scheduler.stopPollingQuery(queryId);
this.queryStore.stopQuery(queryId);
this.invalidate(true, queryId);
this.broadcastQueries();
}

public addQueryListener(queryId: string, listener: QueryListener) {
Expand Down Expand Up @@ -953,7 +963,12 @@ export class QueryManager<TStore> {
}

public stopQuery(queryId: string) {
this.stopQueryInStore(queryId);
this.stopQueryNoBroadcast(queryId);
this.broadcastQueries();
}

private stopQueryNoBroadcast(queryId: string) {
this.stopQueryInStoreNoBroadcast(queryId);
this.removeQuery(queryId);
}

Expand Down

0 comments on commit b37ef99

Please sign in to comment.