Skip to content

Commit

Permalink
Allow passing default value for canonizeResults to InMemoryCache.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Sep 23, 2021
1 parent dba08b7 commit 975da0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cache/inmemory/inMemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface InMemoryCacheConfig extends ApolloReducerConfig {
possibleTypes?: PossibleTypesMap;
typePolicies?: TypePolicies;
resultCacheMaxSize?: number;
canonizeResults?: boolean;
}

type BroadcastOptions = Pick<
Expand All @@ -48,6 +49,7 @@ const defaultConfig: InMemoryCacheConfig = {
dataIdFromObject: defaultDataIdFromObject,
addTypename: true,
resultCaching: true,
canonizeResults: false,
typePolicies: {},
};

Expand Down Expand Up @@ -121,6 +123,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
cache: this,
addTypename: this.addTypename,
resultCacheMaxSize: this.config.resultCacheMaxSize,
canonizeResults: this.config.canonizeResults,
canon: resetResultIdentities
? void 0
: previousReader && previousReader.canon,
Expand Down
5 changes: 4 additions & 1 deletion src/cache/inmemory/readFromStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface StoreReaderConfig {
cache: InMemoryCache,
addTypename?: boolean;
resultCacheMaxSize?: number;
canonizeResults?: boolean;
canon?: ObjectCanon;
}

Expand Down Expand Up @@ -128,6 +129,7 @@ export class StoreReader {
cache: InMemoryCache,
addTypename: boolean;
resultCacheMaxSize?: number;
canonizeResults: boolean;
};

private knownResults = new (
Expand All @@ -143,6 +145,7 @@ export class StoreReader {
this.config = {
...config,
addTypename: config.addTypename !== false,
canonizeResults: !!config.canonizeResults,
};

this.canon = config.canon || new ObjectCanon;
Expand Down Expand Up @@ -231,7 +234,7 @@ export class StoreReader {
rootId = 'ROOT_QUERY',
variables,
returnPartialData = true,
canonizeResults = false,
canonizeResults = this.config.canonizeResults,
}: DiffQueryAgainstStoreOptions): Cache.DiffResult<T> {
const policies = this.config.cache.policies;

Expand Down

0 comments on commit 975da0e

Please sign in to comment.