Skip to content

Commit

Permalink
Remove QueryKeyMaker abstraction. (#4245)
Browse files Browse the repository at this point in the history
It's nice to be able to assume that (sub)queries with equivalent structure
share the same object identities, but the cache will work without that
assumption, and enforcing that discipline is not free, both in terms of
runtime cost and in terms of bundle size.

In the future, the `graphql-tag` tag package should provide a version of
the `gql` template tag function that returns immutable structures that
share object identity where possible.

This commit alone saves 450ish bytes after minification and gzip!
  • Loading branch information
benjamn committed Jan 17, 2019
1 parent f2bcf70 commit 42902f1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 192 deletions.
51 changes: 0 additions & 51 deletions packages/apollo-cache-inmemory/src/__tests__/queryKeyMaker.ts

This file was deleted.

134 changes: 0 additions & 134 deletions packages/apollo-cache-inmemory/src/queryKeyMaker.ts

This file was deleted.

9 changes: 2 additions & 7 deletions packages/apollo-cache-inmemory/src/readFromStore.ts
Expand Up @@ -43,7 +43,6 @@ import { wrap, CacheKeyNode } from './optimism';
export { OptimisticWrapperFunction } from './optimism';

import { DepTrackingCache } from './depTrackingCache';
import { QueryKeyMaker } from './queryKeyMaker';

export type VariableMap = { [name: string]: any };

Expand Down Expand Up @@ -94,8 +93,6 @@ type ExecSelectionSetOptions = {
};

export class StoreReader {
private keyMaker: QueryKeyMaker;

constructor(
private cacheKeyRoot = new CacheKeyNode,
) {
Expand All @@ -105,8 +102,6 @@ export class StoreReader {
executeSelectionSet,
} = reader;

reader.keyMaker = new QueryKeyMaker(cacheKeyRoot);

this.executeStoreQuery = wrap((options: ExecStoreQueryOptions) => {
return executeStoreQuery.call(this, options);
}, {
Expand All @@ -122,7 +117,7 @@ export class StoreReader {
// the cache when relevant data have changed.
if (contextValue.store instanceof DepTrackingCache) {
return reader.cacheKeyRoot.lookup(
reader.keyMaker.forQuery(query).lookupQuery(query),
query,
contextValue.store,
fragmentMatcher,
JSON.stringify(variableValues),
Expand All @@ -143,7 +138,7 @@ export class StoreReader {
}: ExecSelectionSetOptions) {
if (execContext.contextValue.store instanceof DepTrackingCache) {
return reader.cacheKeyRoot.lookup(
reader.keyMaker.forQuery(execContext.query).lookupSelectionSet(selectionSet),
selectionSet,
execContext.contextValue.store,
execContext.fragmentMatcher,
JSON.stringify(execContext.variableValues),
Expand Down

0 comments on commit 42902f1

Please sign in to comment.