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

fix: use nullish coalescing for get method preference (#3812)

Changed files
+13 -7
.changeset
exchanges
packages
core
src
+6
.changeset/twenty-cows-roll.md
···
+
---
+
'@urql/exchange-persisted': patch
+
'@urql/core': patch
+
---
+
+
Use nullish coalescing for `preferGetMethod` and `preferGetForPersistedQueries` so that `false` is kept if set.
+1 -1
exchanges/persisted/src/persistedExchange.test.ts
···
expect(operations[0]).not.toHaveProperty('extensions.persistedQuery');
});
-
it.each([true, 'force', 'within-url-limit'] as const)(
+
it.each([true, false, 'force', 'within-url-limit'] as const)(
'sets `context.preferGetMethod` to %s when `options.preferGetForPersistedQueries` is %s',
async preferGetMethodValue => {
const { exchangeArgs } = makeExchangeArgs();
+4 -5
exchanges/persisted/src/persistedExchange.ts
···
if (!options) options = {};
const preferGetForPersistedQueries =
-
options.preferGetForPersistedQueries || 'within-url-limit';
+
options.preferGetForPersistedQueries != null
+
? options.preferGetForPersistedQueries
+
: 'within-url-limit';
const enforcePersistedQueries = !!options.enforcePersistedQueries;
const hashFn = options.generateHash || hash;
const enableForMutation = !!options.enableForMutation;
···
sha256Hash,
},
};
-
if (
-
persistedOperation.kind === 'query' &&
-
preferGetForPersistedQueries
-
) {
+
if (persistedOperation.kind === 'query') {
persistedOperation.context.preferGetMethod =
preferGetForPersistedQueries;
}
+2 -1
packages/core/src/client.ts
···
fetchSubscriptions: opts.fetchSubscriptions,
fetchOptions: opts.fetchOptions,
fetch: opts.fetch,
-
preferGetMethod: opts.preferGetMethod || 'within-url-limit',
+
preferGetMethod:
+
opts.preferGetMethod != null ? opts.preferGetMethod : 'within-url-limit',
requestPolicy: opts.requestPolicy || 'cache-first',
};