Skip to content

Commit d3b019d

Browse files
authored
major(core|persisted): use GET for queries by default (#3789)
1 parent 230febc commit d3b019d

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

.changeset/giant-pets-buy.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@urql/exchange-persisted': major
3+
'@urql/core': major
4+
---
5+
6+
By default leverage GET for queries where the query-string + variables comes down to less than 2048 characters.
7+
When upgrading it's important to see whether your server supports `GET`, if it doesn't ideally adding support for it
8+
or alternatively setting `preferGetMethod` in the `createClient` method as well as `preferGetForPersistedQueries` for
9+
the persisted exchange to `false`.

exchanges/persisted/src/persistedExchange.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface PersistedExchangeOptions {
4444
* GET requests are frequently used to make GraphQL requests more
4545
* cacheable on CDNs.
4646
*
47-
* @defaultValue `undefined` - disabled
47+
* @defaultValue `within-url-limit` - Use GET requests for persisted queries within the URL limit.
4848
*/
4949
preferGetForPersistedQueries?: OperationContext['preferGetMethod'];
5050
/** Enforces non-automatic persisted queries by ignoring APQ errors.
@@ -137,7 +137,8 @@ export const persistedExchange =
137137
({ forward }) => {
138138
if (!options) options = {};
139139

140-
const preferGetForPersistedQueries = options.preferGetForPersistedQueries;
140+
const preferGetForPersistedQueries =
141+
options.preferGetForPersistedQueries || 'within-url-limit';
141142
const enforcePersistedQueries = !!options.enforcePersistedQueries;
142143
const hashFn = options.generateHash || hash;
143144
const enableForMutation = !!options.enableForMutation;

packages/core/src/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('promisified methods', () => {
148148
fetchOptions: undefined,
149149
fetch: undefined,
150150
suspense: false,
151-
preferGetMethod: undefined,
151+
preferGetMethod: 'within-url-limit',
152152
});
153153
expect(queryResult).toHaveProperty('then');
154154
});
@@ -174,7 +174,7 @@ describe('promisified methods', () => {
174174
fetchOptions: undefined,
175175
fetch: undefined,
176176
suspense: false,
177-
preferGetMethod: undefined,
177+
preferGetMethod: 'within-url-limit',
178178
});
179179
expect(mutationResult).toHaveProperty('then');
180180
});

packages/core/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ export const Client: new (opts: ClientOptions) => Client = function Client(
549549
fetchSubscriptions: opts.fetchSubscriptions,
550550
fetchOptions: opts.fetchOptions,
551551
fetch: opts.fetch,
552-
preferGetMethod: opts.preferGetMethod,
552+
preferGetMethod: opts.preferGetMethod || 'within-url-limit',
553553
requestPolicy: opts.requestPolicy || 'cache-first',
554554
};
555555

0 commit comments

Comments
 (0)