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) - Fix empty and no variables resulting in differing keys (#1695)

authored by

Phil Pluckthun and committed by
GitHub
b27c3944 f5e0b88c

+13 -4
+5
.changeset/two-beers-exist.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Treat empty variables the same as no variables in `@urql/core`'s `createRequest`.
+5
packages/core/src/utils/request.test.ts
··· 2 2 import { gql } from '../gql'; 3 3 import { createRequest } from './request'; 4 4 5 + jest.mock('./hash', () => ({ 6 + hash: jest.requireActual('./hash').hash, 7 + phash: (x: number) => x, 8 + })); 9 + 5 10 it('should hash identical queries identically', () => { 6 11 const reqA = createRequest('{ test }'); 7 12 const reqB = createRequest('{ test }');
+3 -4
packages/core/src/utils/request.ts
··· 78 78 q: string | DocumentNode | TypedDocumentNode<Data, Variables>, 79 79 vars?: Variables 80 80 ): GraphQLRequest<Data, Variables> => { 81 + if (!vars) vars = {} as Variables; 81 82 const query = keyDocument(q); 82 83 return { 83 - key: vars 84 - ? phash(query.__key, stringifyVariables(vars)) >>> 0 85 - : query.__key, 84 + key: phash(query.__key, stringifyVariables(vars)) >>> 0, 86 85 query, 87 - variables: vars || ({} as Variables), 86 + variables: vars, 88 87 }; 89 88 }; 90 89