diff --git a/packages/apollo-client/src/ApolloClient.ts b/packages/apollo-client/src/ApolloClient.ts index 3a270aab636..4f67b238e25 100644 --- a/packages/apollo-client/src/ApolloClient.ts +++ b/packages/apollo-client/src/ApolloClient.ts @@ -63,7 +63,7 @@ export default class ApolloClient implements DataProxy { public link: ApolloLink; public store: DataStore; public cache: ApolloCache; - public queryManager: QueryManager | undefined; + private queryManager: QueryManager | undefined; public disableNetworkFetches: boolean; public version: string; public queryDeduplication: boolean; @@ -418,38 +418,6 @@ export default class ApolloClient implements DataProxy { return execute(this.link, payload); } - /** - * This initializes the query manager that tracks queries and the cache - */ - public initQueryManager(): QueryManager { - if (!this.queryManager) { - this.queryManager = new QueryManager({ - link: this.link, - store: this.store, - queryDeduplication: this.queryDeduplication, - ssrMode: this.ssrMode, - clientAwareness: this.clientAwareness, - onBroadcast: () => { - if (this.devToolsHookCb) { - this.devToolsHookCb({ - action: {}, - state: { - queries: this.queryManager - ? this.queryManager.queryStore.getStore() - : {}, - mutations: this.queryManager - ? this.queryManager.mutationStore.getStore() - : {}, - }, - dataWithOptimisticResults: this.cache.extract(true), - }); - } - }, - }); - } - return this.queryManager; - } - /** * Resets your entire store by clearing out your cache and then re-executing * all of your active queries. This makes it so that you may guarantee that @@ -557,6 +525,38 @@ export default class ApolloClient implements DataProxy { return this.initProxy().restore(serializedState); } + /** + * This initializes the query manager that tracks queries and the cache + */ + private initQueryManager(): QueryManager { + if (!this.queryManager) { + this.queryManager = new QueryManager({ + link: this.link, + store: this.store, + queryDeduplication: this.queryDeduplication, + ssrMode: this.ssrMode, + clientAwareness: this.clientAwareness, + onBroadcast: () => { + if (this.devToolsHookCb) { + this.devToolsHookCb({ + action: {}, + state: { + queries: this.queryManager + ? this.queryManager.queryStore.getStore() + : {}, + mutations: this.queryManager + ? this.queryManager.mutationStore.getStore() + : {}, + }, + dataWithOptimisticResults: this.cache.extract(true), + }); + } + }, + }); + } + return this.queryManager; + } + /** * Initializes a data proxy for this client instance if one does not already * exist and returns either a previously initialized proxy instance or the diff --git a/packages/apollo-client/src/__tests__/client.ts b/packages/apollo-client/src/__tests__/client.ts index 27aed28de30..5ffd282a666 100644 --- a/packages/apollo-client/src/__tests__/client.ts +++ b/packages/apollo-client/src/__tests__/client.ts @@ -28,11 +28,11 @@ describe('client', () => { cache: new InMemoryCache(), }); - expect(client.queryManager).toBeUndefined(); + expect((client as any).queryManager).toBeUndefined(); // We only create the query manager on the first query - client.initQueryManager(); - expect(client.queryManager).toBeDefined(); + (client as any).initQueryManager(); + expect((client as any).queryManager).toBeDefined(); expect(client.cache).toBeDefined(); });