Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(core) - mark query.__key as non-enumerable (#1870)

* mark query.__key as non-enumerable

* add test

authored by

Jovi De Croock and committed by
GitHub
792c6a11 07ace8a5

+23 -1
+5
.changeset/rude-pumpkins-yawn.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Fix mark `query.__key` as non-enumerable so `formatDocument` does not restore previous invocations when cloning the gql-ast.
+9
packages/core/src/utils/typenames.test.ts
··· 49 49 expect(expectedKey).toBe(actualKey); 50 50 }); 51 51 52 + it('does not preserve the referential integrity with a cloned object', () => { 53 + const doc = parse(`{ id todos { id } }`); 54 + const formattedDoc = formatDocument(doc); 55 + expect(formattedDoc).not.toBe(doc); 56 + const query = { ...formattedDoc }; 57 + const reformattedDoc = formatDocument(query); 58 + expect(reformattedDoc).not.toBe(doc); 59 + }); 60 + 52 61 it('preserves custom properties', () => { 53 62 const doc = parse(`{ todos { id } }`) as any; 54 63 doc.documentId = '123';
+9 -1
packages/core/src/utils/typenames.ts
··· 76 76 Field: formatNode, 77 77 InlineFragment: formatNode, 78 78 }) as KeyedDocumentNode; 79 + 79 80 // Ensure that the hash of the resulting document won't suddenly change 80 - result.__key = query.__key; 81 + // we are marking __key as non-enumerable so when external exchanges use visit 82 + // to manipulate a document we won't restore the previous query due to the __key 83 + // property. 84 + Object.defineProperty(result, '__key', { 85 + value: query.__key, 86 + enumerable: false, 87 + }); 88 + 81 89 formattedDocs.set(query.__key, result); 82 90 } 83 91