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

major(core|persisted): use GET for queries by default (#3789)

Changed files
+15 -5
.changeset
exchanges
persisted
packages
+9
.changeset/giant-pets-buy.md
···
···
+
---
+
'@urql/exchange-persisted': major
+
'@urql/core': major
+
---
+
+
By default leverage GET for queries where the query-string + variables comes down to less than 2048 characters.
+
When upgrading it's important to see whether your server supports `GET`, if it doesn't ideally adding support for it
+
or alternatively setting `preferGetMethod` in the `createClient` method as well as `preferGetForPersistedQueries` for
+
the persisted exchange to `false`.
+3 -2
exchanges/persisted/src/persistedExchange.ts
···
* GET requests are frequently used to make GraphQL requests more
* cacheable on CDNs.
*
-
* @defaultValue `undefined` - disabled
*/
preferGetForPersistedQueries?: OperationContext['preferGetMethod'];
/** Enforces non-automatic persisted queries by ignoring APQ errors.
···
({ forward }) => {
if (!options) options = {};
-
const preferGetForPersistedQueries = options.preferGetForPersistedQueries;
const enforcePersistedQueries = !!options.enforcePersistedQueries;
const hashFn = options.generateHash || hash;
const enableForMutation = !!options.enableForMutation;
···
* GET requests are frequently used to make GraphQL requests more
* cacheable on CDNs.
*
+
* @defaultValue `within-url-limit` - Use GET requests for persisted queries within the URL limit.
*/
preferGetForPersistedQueries?: OperationContext['preferGetMethod'];
/** Enforces non-automatic persisted queries by ignoring APQ errors.
···
({ forward }) => {
if (!options) options = {};
+
const preferGetForPersistedQueries =
+
options.preferGetForPersistedQueries || 'within-url-limit';
const enforcePersistedQueries = !!options.enforcePersistedQueries;
const hashFn = options.generateHash || hash;
const enableForMutation = !!options.enableForMutation;
+2 -2
packages/core/src/client.test.ts
···
fetchOptions: undefined,
fetch: undefined,
suspense: false,
-
preferGetMethod: undefined,
});
expect(queryResult).toHaveProperty('then');
});
···
fetchOptions: undefined,
fetch: undefined,
suspense: false,
-
preferGetMethod: undefined,
});
expect(mutationResult).toHaveProperty('then');
});
···
fetchOptions: undefined,
fetch: undefined,
suspense: false,
+
preferGetMethod: 'within-url-limit',
});
expect(queryResult).toHaveProperty('then');
});
···
fetchOptions: undefined,
fetch: undefined,
suspense: false,
+
preferGetMethod: 'within-url-limit',
});
expect(mutationResult).toHaveProperty('then');
});
+1 -1
packages/core/src/client.ts
···
fetchSubscriptions: opts.fetchSubscriptions,
fetchOptions: opts.fetchOptions,
fetch: opts.fetch,
-
preferGetMethod: opts.preferGetMethod,
requestPolicy: opts.requestPolicy || 'cache-first',
};
···
fetchSubscriptions: opts.fetchSubscriptions,
fetchOptions: opts.fetchOptions,
fetch: opts.fetch,
+
preferGetMethod: opts.preferGetMethod || 'within-url-limit',
requestPolicy: opts.requestPolicy || 'cache-first',
};