From a69b7f78c7cb273c9bb9da831939b26a8e48c692 Mon Sep 17 00:00:00 2001 From: Alek Angelov Date: Tue, 13 Dec 2022 12:19:47 +0100 Subject: [PATCH] feat: add prevent broadcast option in QueryManager --- src/core/ApolloClient.ts | 7 +++++++ src/core/QueryManager.ts | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index b26da37e579..fae22119ca4 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -60,6 +60,7 @@ export type ApolloClientOptions = { fragmentMatcher?: FragmentMatcher; name?: string; version?: string; + notifyOnTeardown?: boolean; }; // Though mergeOptions now resides in @apollo/client/utilities, it was @@ -123,6 +124,10 @@ export class ApolloClient implements DataProxy { * version of your client, which you may want to increment on * new builds. This is NOT the version of Apollo Client that * you are using. + * + * @param notifyOnTeardown Defaults to true, but when set to false will + * prevent the client from notifying any active queries. + * Could result in substantial performance gains in some cases. */ constructor(options: ApolloClientOptions) { const { @@ -147,6 +152,7 @@ export class ApolloClient implements DataProxy { fragmentMatcher, name: clientAwarenessName, version: clientAwarenessVersion, + notifyOnTeardown = true } = options; let { link } = options; @@ -253,6 +259,7 @@ export class ApolloClient implements DataProxy { }); } } : void 0, + notifyOnTeardown }); } diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index 36fac27ef13..9b6a58d3bbf 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -85,6 +85,7 @@ export class QueryManager { public link: ApolloLink; public defaultOptions: DefaultOptions; + public readonly notifyOnTeardown: boolean; public readonly assumeImmutableResults: boolean; public readonly ssrMode: boolean; @@ -115,6 +116,7 @@ export class QueryManager { clientAwareness = {}, localState, assumeImmutableResults, + notifyOnTeardown = true }: { cache: ApolloCache; link: ApolloLink; @@ -125,6 +127,7 @@ export class QueryManager { clientAwareness?: Record; localState?: LocalState; assumeImmutableResults?: boolean; + notifyOnTeardown?: boolean; }) { this.cache = cache; this.link = link; @@ -134,6 +137,7 @@ export class QueryManager { this.localState = localState || new LocalState({ cache }); this.ssrMode = ssrMode; this.assumeImmutableResults = !!assumeImmutableResults; + this.notifyOnTeardown = !!notifyOnTeardown; if ((this.onBroadcast = onBroadcast)) { this.mutationStore = Object.create(null); } @@ -915,6 +919,7 @@ export class QueryManager { public stopQuery(queryId: string) { this.stopQueryNoBroadcast(queryId); + if(!this.notifyOnTeardown) return; this.broadcastQueries(); }