diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 6aa5c6263d8..50ff65301af 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -96,20 +96,15 @@ export class InMemoryCache extends ApolloCache { return maybeBroadcastWatch.call(this, c); }, { makeCacheKey(c: Cache.WatchOptions) { - if (c.previousResult) { - // If a previousResult was provided, assume the caller would prefer - // to compare the previous data to the new data to determine whether - // to broadcast, so we should disable caching by returning here, to - // give maybeBroadcastWatch a chance to do that comparison. - return; - } - - if (supportsResultCaching(cache.data)) { - // Return a cache key (thus enabling caching) only if we're currently - // using a data store that can track cache dependencies. + // Return a cache key (thus enabling result caching) only if we're + // currently using a data store that can track cache dependencies. + const store = c.optimistic ? cache.optimisticData : cache.data; + if (supportsResultCaching(store)) { + const { optimistic, rootId, variables } = c; return cache.cacheKeyRoot.lookup( c.query, - JSON.stringify(c.variables), + store, + JSON.stringify({ optimistic, rootId, variables }), ); } } @@ -136,7 +131,6 @@ export class InMemoryCache extends ApolloCache { query: options.query, variables: options.variables, rootId: options.rootId, - previousResult: options.previousResult, config: this.config, }) || null; } @@ -159,7 +153,6 @@ export class InMemoryCache extends ApolloCache { query: options.query, variables: options.variables, returnPartialData: options.returnPartialData, - previousResult: options.previousResult, config: this.config, }); } @@ -305,7 +298,6 @@ export class InMemoryCache extends ApolloCache { this.diff({ query: c.query, variables: c.variables, - previousResult: c.previousResult && c.previousResult(), optimistic: c.optimistic, }), ); diff --git a/src/cache/inmemory/readFromStore.ts b/src/cache/inmemory/readFromStore.ts index ec26ae65b65..e3f08d148a9 100644 --- a/src/cache/inmemory/readFromStore.ts +++ b/src/cache/inmemory/readFromStore.ts @@ -26,7 +26,6 @@ import { getMainDefinition, getQueryDefinition, } from '../../utilities/graphql/getFromAST'; -import { isEqual } from '../../utilities/common/isEqual'; import { maybeDeepFreeze } from '../../utilities/common/maybeDeepFreeze'; import { mergeDeepArray } from '../../utilities/common/mergeDeep'; import { Cache } from '../core/types/Cache'; @@ -141,10 +140,6 @@ export class StoreReader { * * @param {Object} [variables] A map from the name of a variable to its value. These variables can * be referenced by the query document. - * - * @param {any} previousResult The previous result returned by this function for the same query. - * If nothing in the store changed since that previous result then values from the previous result - * will be returned to preserve referential equality. */ public readQueryFromStore( options: ReadQueryOptions, @@ -160,14 +155,12 @@ export class StoreReader { * identify if any data was missing from the store. * @param {DocumentNode} query A parsed GraphQL query document * @param {Store} store The Apollo Client store object - * @param {any} previousResult The previous result returned by this function for the same query * @return {result: Object, complete: [boolean]} */ public diffQueryAgainstStore({ store, query, variables, - previousResult, returnPartialData = true, rootId = 'ROOT_QUERY', config, @@ -205,12 +198,6 @@ export class StoreReader { }); } - if (previousResult) { - if (isEqual(previousResult, execResult.result)) { - execResult.result = previousResult; - } - } - return { result: execResult.result, complete: !hasMissingFields,