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)

authored by

Jovi De Croock and committed by
GitHub
d3b019d5 230febcc

+15 -5
+9
.changeset/giant-pets-buy.md
··· 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`.
+3 -2
exchanges/persisted/src/persistedExchange.ts
··· 44 44 * GET requests are frequently used to make GraphQL requests more 45 45 * cacheable on CDNs. 46 46 * 47 - * @defaultValue `undefined` - disabled 47 + * @defaultValue `within-url-limit` - Use GET requests for persisted queries within the URL limit. 48 48 */ 49 49 preferGetForPersistedQueries?: OperationContext['preferGetMethod']; 50 50 /** Enforces non-automatic persisted queries by ignoring APQ errors. ··· 137 137 ({ forward }) => { 138 138 if (!options) options = {}; 139 139 140 - const preferGetForPersistedQueries = options.preferGetForPersistedQueries; 140 + const preferGetForPersistedQueries = 141 + options.preferGetForPersistedQueries || 'within-url-limit'; 141 142 const enforcePersistedQueries = !!options.enforcePersistedQueries; 142 143 const hashFn = options.generateHash || hash; 143 144 const enableForMutation = !!options.enableForMutation;
+2 -2
packages/core/src/client.test.ts
··· 148 148 fetchOptions: undefined, 149 149 fetch: undefined, 150 150 suspense: false, 151 - preferGetMethod: undefined, 151 + preferGetMethod: 'within-url-limit', 152 152 }); 153 153 expect(queryResult).toHaveProperty('then'); 154 154 }); ··· 174 174 fetchOptions: undefined, 175 175 fetch: undefined, 176 176 suspense: false, 177 - preferGetMethod: undefined, 177 + preferGetMethod: 'within-url-limit', 178 178 }); 179 179 expect(mutationResult).toHaveProperty('then'); 180 180 });
+1 -1
packages/core/src/client.ts
··· 549 549 fetchSubscriptions: opts.fetchSubscriptions, 550 550 fetchOptions: opts.fetchOptions, 551 551 fetch: opts.fetch, 552 - preferGetMethod: opts.preferGetMethod, 552 + preferGetMethod: opts.preferGetMethod || 'within-url-limit', 553 553 requestPolicy: opts.requestPolicy || 'cache-first', 554 554 }; 555 555