Skip to content

Commit b37ef99

Browse files
authored
Merge pull request #4359 from apollographql/stop-QueryManager-more-thoroughly
Prevent unhandled rejections by stopping QueryManager more thoroughly.
2 parents f94cd30 + b3961b9 commit b37ef99

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

packages/apollo-client/src/core/QueryManager.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export class QueryManager<TStore> {
113113
*/
114114
public stop() {
115115
this.scheduler.stop();
116+
117+
this.queries.forEach((_info, queryId) => {
118+
this.stopQueryNoBroadcast(queryId);
119+
});
120+
116121
this.fetchQueryRejectFns.forEach(reject => {
117122
reject(new Error('QueryManager stopped while query was in flight'));
118123
});
@@ -721,9 +726,14 @@ export class QueryManager<TStore> {
721726
}
722727

723728
public stopQueryInStore(queryId: string) {
729+
this.stopQueryInStoreNoBroadcast(queryId);
730+
this.broadcastQueries();
731+
}
732+
733+
private stopQueryInStoreNoBroadcast(queryId: string) {
734+
this.scheduler.stopPollingQuery(queryId);
724735
this.queryStore.stopQuery(queryId);
725736
this.invalidate(true, queryId);
726-
this.broadcastQueries();
727737
}
728738

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

955965
public stopQuery(queryId: string) {
956-
this.stopQueryInStore(queryId);
966+
this.stopQueryNoBroadcast(queryId);
967+
this.broadcastQueries();
968+
}
969+
970+
private stopQueryNoBroadcast(queryId: string) {
971+
this.stopQueryInStoreNoBroadcast(queryId);
957972
this.removeQuery(queryId);
958973
}
959974

0 commit comments

Comments
 (0)