diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 8f65cbd26a1..eef9d6a2ba0 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -176,21 +176,29 @@ export abstract class ApolloCache implements DataProxy { options: Cache.UpdateQueryOptions, update: (data: TData | null) => TData | null | void, ): TData | null { - const value = this.readQuery(options); - const data = update(value); - if (data === void 0 || data === null) return value; - this.writeQuery({ ...options, data }); - return data; + return this.batch({ + update(cache) { + const value = cache.readQuery(options); + const data = update(value); + if (data === void 0 || data === null) return value; + cache.writeQuery({ ...options, data }); + return data; + }, + }); } public updateFragment( options: Cache.UpdateFragmentOptions, update: (data: TData | null) => TData | null | void, ): TData | null { - const value = this.readFragment(options); - const data = update(value); - if (data === void 0 || data === null) return value; - this.writeFragment({ ...options, data }); - return data; + return this.batch({ + update(cache) { + const value = cache.readFragment(options); + const data = update(value); + if (data === void 0 || data === null) return value; + cache.writeFragment({ ...options, data }); + return data; + }, + }); } }