···11+---
22+'@urql/core': patch
33+---
44+55+Change how we calculate the `OperationKey` to take files into account, before we
66+would encode them to `null` resulting in every mutation with the same variables
77+(excluding the files) to have the same key. This resulted in mutations that upload
88+different files at the same time to share a result in GraphCache.
+11-10
packages/core/src/utils/variables.ts
···33const seen: Set<any> = new Set();
44const cache: WeakMap<any, any> = new WeakMap();
5566-const stringify = (x: any): string => {
66+const stringify = (x: any, includeFiles: boolean): string => {
77 if (x === null || seen.has(x)) {
88 return 'null';
99 } else if (typeof x !== 'object') {
1010 return JSON.stringify(x) || '';
1111 } else if (x.toJSON) {
1212- return stringify(x.toJSON());
1212+ return stringify(x.toJSON(), includeFiles);
1313 } else if (Array.isArray(x)) {
1414 let out = '[';
1515 for (const value of x) {
1616 if (out.length > 1) out += ',';
1717- out += stringify(value) || 'null';
1717+ out += stringify(value, includeFiles) || 'null';
1818 }
1919 out += ']';
2020 return out;
2121 } else if (
2222- (FileConstructor !== NoopConstructor && x instanceof FileConstructor) ||
2323- (BlobConstructor !== NoopConstructor && x instanceof BlobConstructor)
2222+ !includeFiles &&
2323+ ((FileConstructor !== NoopConstructor && x instanceof FileConstructor) ||
2424+ (BlobConstructor !== NoopConstructor && x instanceof BlobConstructor))
2425 ) {
2526 return 'null';
2627 }
···3334 ) {
3435 const key = cache.get(x) || Math.random().toString(36).slice(2);
3536 cache.set(x, key);
3636- return stringify({ __key: key });
3737+ return stringify({ __key: key }, includeFiles);
3738 }
38393940 seen.add(x);
4041 let out = '{';
4142 for (const key of keys) {
4242- const value = stringify(x[key]);
4343+ const value = stringify(x[key], includeFiles);
4344 if (value) {
4445 if (out.length > 1) out += ',';
4545- out += stringify(key) + ':' + value;
4646+ out += stringify(key, includeFiles) + ':' + value;
4647 }
4748 }
4849···7980 * replacing their values, which remain stable for the objects’
8081 * instance.
8182 */
8282-export const stringifyVariables = (x: any): string => {
8383+export const stringifyVariables = (x: any, includeFiles?: boolean): string => {
8384 seen.clear();
8484- return stringify(x);
8585+ return stringify(x, includeFiles || false);
8586};
86878788class NoopConstructor {}