Skip to content

Commit

Permalink
Use canonicalStringify instead of JSON.stringify in more places.
Browse files Browse the repository at this point in the history
Possible thanks to #8222.
  • Loading branch information
benjamn committed May 25, 2021
1 parent 4da232c commit 5dc9db1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cache/inmemory/inMemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
// 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 }),
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cache/inmemory/readFromStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -235,7 +235,7 @@ export class StoreReader {
query,
policies,
variables,
varString: JSON.stringify(variables),
varString: canonicalStringify(variables),
canonizeResults,
fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
path: [],
Expand Down
3 changes: 2 additions & 1 deletion src/cache/inmemory/writeToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit 5dc9db1

Please sign in to comment.