Skip to content

Commit

Permalink
Remove QueryManager from public ApolloClient API.
Browse files Browse the repository at this point in the history
By privatizing the QueryManager, we give ourselves room to change its API
in drastic ways without affecting the ApolloClient API.
  • Loading branch information
benjamn committed Jan 17, 2019
1 parent 70c4cf3 commit d4f3346
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
66 changes: 33 additions & 33 deletions packages/apollo-client/src/ApolloClient.ts
Expand Up @@ -63,7 +63,7 @@ export default class ApolloClient<TCacheShape> implements DataProxy {
public link: ApolloLink;
public store: DataStore<TCacheShape>;
public cache: ApolloCache<TCacheShape>;
public queryManager: QueryManager<TCacheShape> | undefined;
private queryManager: QueryManager<TCacheShape> | undefined;
public disableNetworkFetches: boolean;
public version: string;
public queryDeduplication: boolean;
Expand Down Expand Up @@ -418,38 +418,6 @@ export default class ApolloClient<TCacheShape> implements DataProxy {
return execute(this.link, payload);
}

/**
* This initializes the query manager that tracks queries and the cache
*/
public initQueryManager(): QueryManager<TCacheShape> {
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
Expand Down Expand Up @@ -557,6 +525,38 @@ export default class ApolloClient<TCacheShape> implements DataProxy {
return this.initProxy().restore(serializedState);
}

/**
* This initializes the query manager that tracks queries and the cache
*/
private initQueryManager(): QueryManager<TCacheShape> {
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
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-client/src/__tests__/client.ts
Expand Up @@ -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();
});

Expand Down

0 comments on commit d4f3346

Please sign in to comment.