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) - Shorten queries for hashing (#911)

* remove comments and whitespace from our own queries

* add changeset

* add comment after opening bracket in test

* Remove location data from parsed queries

Co-authored-by: Phil Pluckthun <phil@kitten.sh>

authored by

Jovi De Croock
Phil Pluckthun
and committed by
GitHub
873ba9db ac642142

+23 -2
+5
.changeset/hip-adults-look.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Remove whitespace and comments from string-queries
+14
packages/core/src/utils/request.test.ts
··· 73 73 variables: { test: 5 }, 74 74 }); 75 75 }); 76 + 77 + it('should remove comments', () => { 78 + const doc = ` 79 + { #query 80 + # broken 81 + test 82 + } 83 + `; 84 + const val = createRequest(doc); 85 + expect(print(val.query)).toBe(`{ 86 + test 87 + } 88 + `); 89 + });
+4 -2
packages/core/src/utils/request.ts
··· 7 7 [key: number]: DocumentNode; 8 8 } 9 9 10 - const hashQuery = (q: string): number => hash(q.replace(/[\s,]+/g, ' ').trim()); 10 + const hashQuery = (q: string): number => 11 + hash(q.replace(/([\s,]|#[^\n\r]+)+/g, ' ').trim()); 11 12 12 13 const docs: Documents = Object.create(null); 13 14 ··· 19 20 let query: DocumentNode; 20 21 if (typeof q === 'string') { 21 22 key = hashQuery(q); 22 - query = docs[key] !== undefined ? docs[key] : parse(q); 23 + query = 24 + docs[key] !== undefined ? docs[key] : parse(q, { noLocation: true }); 23 25 } else if ((q as any).__key !== undefined) { 24 26 key = (q as any).__key; 25 27 query = q;