From 5dc9db1b98d8f5b04ab7dbdc061ad966816ec4d5 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 24 May 2021 11:47:09 -0400 Subject: [PATCH] Use canonicalStringify instead of JSON.stringify in more places. Possible thanks to #8222. --- src/cache/inmemory/inMemoryCache.ts | 2 +- src/cache/inmemory/readFromStore.ts | 4 ++-- src/cache/inmemory/writeToStore.ts | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index a154204250d..dc28a4868b3 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -137,7 +137,7 @@ export class InMemoryCache extends ApolloCache { // separation is to include c.callback in the cache key for // maybeBroadcastWatch calls. See issue #5733. c.callback, - JSON.stringify({ optimistic, rootId, variables }), + canonicalStringify({ optimistic, rootId, variables }), ); } } diff --git a/src/cache/inmemory/readFromStore.ts b/src/cache/inmemory/readFromStore.ts index 36caf7ea1d4..b0ddc9fcad2 100644 --- a/src/cache/inmemory/readFromStore.ts +++ b/src/cache/inmemory/readFromStore.ts @@ -36,7 +36,7 @@ import { getTypenameFromStoreObject } from './helpers'; import { Policies } from './policies'; import { InMemoryCache } from './inMemoryCache'; import { MissingFieldError } from '../core/types/common'; -import { ObjectCanon } from './object-canon'; +import { canonicalStringify, ObjectCanon } from './object-canon'; export type VariableMap = { [name: string]: any }; @@ -235,7 +235,7 @@ export class StoreReader { query, policies, variables, - varString: JSON.stringify(variables), + varString: canonicalStringify(variables), canonizeResults, fragmentMap: createFragmentMap(getFragmentDefinitions(query)), path: [], diff --git a/src/cache/inmemory/writeToStore.ts b/src/cache/inmemory/writeToStore.ts index 091e47884db..d50f54ecdec 100644 --- a/src/cache/inmemory/writeToStore.ts +++ b/src/cache/inmemory/writeToStore.ts @@ -28,6 +28,7 @@ import { StoreReader } from './readFromStore'; import { InMemoryCache } from './inMemoryCache'; import { EntityStore } from './entityStore'; import { Cache } from '../../core'; +import { canonicalStringify } from './object-canon'; export interface WriteContext extends ReadMergeModifyContext { readonly written: { @@ -81,7 +82,7 @@ export class StoreWriter { return merger.merge(existing, incoming) as T; }, variables, - varString: JSON.stringify(variables), + varString: canonicalStringify(variables), fragmentMap: createFragmentMap(getFragmentDefinitions(query)), overwrite: !!overwrite, },