···11+---
22+'@urql/core': major
33+---
44+55+Remove `defaultExchanges` from `@urql/core` and make `exchanges` a required property on `Client` construction.
66+In doing so we make the `urql` package more tree-shakeable as the three default exchanges are in no code paths
77+meaning they can be removed if not used.
88+99+A migration would look as follows if you are currently creating a client without exchanges
1010+1111+```js
1212+import { createClient, cacheExchange, fetchExchange } from '@urql/core'
1313+1414+const client = createClient({
1515+ url: '',
1616+ exchanges: [cacheExchange, fetchExchange]
1717+});
1818+```
+6
.changeset/honest-apples-join.md
···11+---
22+'@urql/preact': major
33+'urql': major
44+---
55+66+Remove the default `Client` from `Context`. Previously, `urql` kept a legacy default client in its context, with default exchanges and calling an API at `/graphql`. This has now been removed and you will have to create your own `Client` if you were relying on this behaviour.
-1
docs/advanced/authoring-exchanges.md
···283283```js
284284import { dedupExchange, cacheExchange, fetchExchange } from 'urql';
285285286286-// Also exported as `defaultExchanges`:
287286[dedupExchange, cacheExchange, fetchExchange];
288287```
289288
+12-6
docs/advanced/subscriptions.md
···1313To add support for subscriptions we need to add the `subscriptionExchange` to our `Client`.
14141515```js
1616-import { Client, defaultExchanges, subscriptionExchange } from 'urql';
1616+import { Client, dedupExchange, cacheExchange, fetchExchange, subscriptionExchange } from 'urql';
17171818const client = new Client({
1919 url: 'http://localhost:3000/graphql',
2020 exchanges: [
2121- ...defaultExchanges,
2121+ dedupExchange,
2222+ cacheExchange,
2323+ fetchExchange,
2224 subscriptionExchange({
2325 forwardSubscription,
2426 }),
···4547For backends supporting `graphql-ws`, we recommend using the [graphql-ws](https://github.com/enisdenjo/graphql-ws) client.
46484749```js
4848-import { createClient, defaultExchanges, subscriptionExchange } from 'urql';
5050+import { createClient, dedupExchange, cacheExchange, fetchExchange, subscriptionExchange } from 'urql';
4951import { createClient as createWSClient } from 'graphql-ws';
50525153const wsClient = createWSClient({
···5557const client = createClient({
5658 url: '/graphql',
5759 exchanges: [
5858- ...defaultExchanges,
6060+ dedupExchange,
6161+ cacheExchange,
6262+ fetchExchange,
5963 subscriptionExchange({
6064 forwardSubscription: request => ({
6165 subscribe: sink => ({
···8185> The `subscriptions-transport-ws` package isn't actively maintained. If your API supports the new protocol or you can swap the package out, consider using [`graphql-ws`](#setting-up-graphql-ws) instead.
82868387```js
8484-import { Client, defaultExchanges, subscriptionExchange } from 'urql';
8888+import { Client, dedupExchange, cacheExchange, fetchExchange, subscriptionExchange } from 'urql';
8589import { SubscriptionClient } from 'subscriptions-transport-ws';
86908791const subscriptionClient = new SubscriptionClient('ws://localhost/graphql', { reconnect: true });
···8993const client = new Client({
9094 url: '/graphql',
9195 exchanges: [
9292- ...defaultExchanges,
9696+ dedupExchange,
9797+ cacheExchange,
9898+ fetchExchange,
9399 subscriptionExchange({
94100 forwardSubscription: request => subscriptionClient.request(request),
95101 }),
+1-10
docs/api/core.md
···22222323| Input | Type | Description |
2424| ----------------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2525-| `exchanges` | `Exchange[]` | An array of `Exchange`s that the client should use instead of the list of `defaultExchanges` |
2525+| `exchanges` | `Exchange[]` | An array of `Exchange`s that the client should use |
2626| `url` | `string` | The GraphQL API URL as used by `fetchExchange` |
2727| `fetchOptions` | `RequestInit \| () => RequestInit` | Additional `fetchOptions` that `fetch` in `fetchExchange` should use to make a request |
2828| `fetch` | `typeof fetch` | An alternative implementation of `fetch` that will be used by the `fetchExchange` instead of `window.fetch` |
···522522this problem.
523523524524It's used by the [`Client`](#client) when the `maskTypename` option is enabled.
525525-526526-### defaultExchanges
527527-528528-This is an array of the default `Exchange`s that the `Client` uses when the `exchanges` option isn't
529529-passed.
530530-531531-```js
532532-const defaultExchanges = [dedupExchange, cacheExchange, fetchExchange];
533533-```
534525535526### composeExchanges
536527
+2-1
docs/architecture.md
···4545extra information on how the GraphQL requests are executed.
46464747```js
4848-import { Client } from '@urql/core';
4848+import { Client, dedupExchange, cacheExchange, fetchExchange } from '@urql/core';
49495050new Client({
5151 url: 'http://localhost:3000/graphql',
5252 requestPolicy: 'cache-first',
5353+ exchanges: [dedupExchange, cacheExchange, fetchExchange]
5354});
5455```
5556
+5-7
docs/basics/core.md
···134134create the GraphQL client. This central `Client` manages all of our GraphQL requests and results.
135135136136```js
137137-import { createClient } from '@urql/core';
137137+import { createClient, dedupExchange, cacheExchange, fetchExchange } from '@urql/core';
138138139139const client = createClient({
140140 url: 'http://localhost:3000/graphql',
141141+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
141142});
142143```
143144···153154```js
154155const client = createClient({
155156 url: 'http://localhost:3000/graphql',
157157+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
156158 fetchOptions: () => {
157159 const token = getToken();
158160 return {
···168170without it. However, another important option on the `Client` is the `exchanges` option.
169171170172This option passes a list of exchanges to the `Client`, which tell it how to execute our requests
171171-and how to cache data in a certain order. By default, this will be populated with the list of
172172-`defaultExchanges`.
173173+and how to cache data in a certain order.
173174174175```js
175175-import { createClient, defaultExchanges } from '@urql/core';
176176+import { createClient, dedupExchange, cacheExchange, fetchExchange } from '@urql/core';
176177177178const client = createClient({
178179 url: 'http://localhost:3000/graphql',
179179- // the default:
180180- exchanges: defaultExchanges,
181181- // the same as:
182180 exchanges: [dedupExchange, cacheExchange, fetchExchange],
183181});
184182```
+6-2
docs/basics/react-preact.md
···4141create the GraphQL client. This central `Client` manages all of our GraphQL requests and results.
42424343```js
4444-import { createClient } from 'urql';
4444+import { createClient, dedupExchange, cacheExchange, fetchExchange } from 'urql';
45454646const client = createClient({
4747 url: 'http://localhost:3000/graphql',
4848+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
4849});
4950```
5051···6061```js
6162const client = createClient({
6263 url: 'http://localhost:3000/graphql',
6464+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
6365 fetchOptions: () => {
6466 const token = getToken();
6567 return {
···7678the `Provider` export.
77797880```jsx
7979-import { createClient, Provider } from 'urql';
8181+import { createClient, Provider, dedupExchange, cacheExchange, fetchExchange } from 'urql';
80828183const client = createClient({
8284 url: 'http://localhost:3000/graphql',
8585+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
8386});
84878588const App = () => (
···245248246249const client = createClient({
247250 url: 'http://localhost:3000/graphql',
251251+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
248252 // every operation will by default use cache-and-network rather
249253 // than cache-first now:
250254 requestPolicy: 'cache-and-network',
+6-2
docs/basics/svelte.md
···4848the GraphQL client. This central `Client` manages all of our GraphQL requests and results.
49495050```js
5151-import { createClient } from '@urql/svelte';
5151+import { createClient, dedupExchange, cacheExchange, fetchExchange } from '@urql/svelte';
52525353const client = createClient({
5454 url: 'http://localhost:3000/graphql',
5555+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
5556});
5657```
5758···6768```js
6869const client = createClient({
6970 url: 'http://localhost:3000/graphql',
7171+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
7072 fetchOptions: () => {
7173 const token = getToken();
7274 return {
···85878688```html
8789<script>
8888- import { createClient, setContextClient } from '@urql/svelte';
9090+ import { createClient, setContextClient, dedupExchange, cacheExchange, fetchExchange } from '@urql/svelte';
89919092 const client = createClient({
9193 url: 'http://localhost:3000/graphql',
9494+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
9295 });
93969497 setContextClient(client);
···292295293296const client = createClient({
294297 url: 'http://localhost:3000/graphql',
298298+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
295299 // every operation will by default use cache-and-network rather
296300 // than cache-first now:
297301 requestPolicy: 'cache-and-network',
+7-3
docs/basics/vue.md
···3737the GraphQL client. This central `Client` manages all of our GraphQL requests and results.
38383939```js
4040-import { createClient } from '@urql/vue';
4040+import { createClient, dedupExchange, cacheExchange, fetchExchange } from '@urql/vue';
41414242const client = createClient({
4343 url: 'http://localhost:3000/graphql',
4444+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
4445});
4546```
4647···5657```js
5758const client = createClient({
5859 url: 'http://localhost:3000/graphql',
6060+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
5961 fetchOptions: () => {
6062 const token = getToken();
6163 return {
···77797880```html
7981<script>
8080- import { createClient, provideClient } from '@urql/vue';
8282+ import { createClient, provideClient, dedupExchange, cacheExchange, fetchExchange } from '@urql/vue';
81838284 const client = createClient({
8385 url: 'http://localhost:3000/graphql',
8686+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
8487 });
85888689 provideClient(client);
···361364we may also change the `Client`'s default `requestPolicy` by passing it there.
362365363366```js
364364-import { createClient } from '@urql/vue';
367367+import { createClient, dedupExchange, cacheExchange, fetchExchange } from '@urql/vue';
365368366369const client = createClient({
367370 url: 'http://localhost:3000/graphql',
371371+ exchanges: [dedupExchange, cacheExchange, fetchExchange],
368372 // every operation will by default use cache-and-network rather
369373 // than cache-first now:
370374 requestPolicy: 'cache-and-network',
···23232424import { DocumentNode } from 'graphql';
25252626-import { composeExchanges, defaultExchanges } from './exchanges';
2626+import { composeExchanges } from './exchanges';
2727import { fallbackExchange } from './exchanges/fallback';
28282929import {
···111111 * This is the basis for how `urql` handles GraphQL operations, and exchanges handle the creation, execution,
112112 * and control flow of exchanges for the `Client`.
113113 *
114114- * When this option is left out, the `Client` defaults to a list of {@link defaultExchanges}. By default, these
115115- * will implement deduping, caching (via a document cache), and fetching (GraphQL over HTTP).
114114+ * To easily get started you should consider using the {@link dedupExchange}, {@link cacheExchange} and {@link fetchExchange}
115115+ * these are all exported from the core package.
116116 *
117117 * @see {@link https://formidable.com/open-source/urql/docs/architecture/#the-client-and-exchanges} for more information
118118 * on what `Exchange`s are and how they work.
119119 */
120120- exchanges?: Exchange[];
120120+ exchanges: Exchange[];
121121 /** A configuration flag indicating whether support for "Suspense" is activated.
122122 *
123123 * @remarks
···812812 dispatchDebug = next as ExchangeInput['dispatchDebug'];
813813 }
814814815815- const exchanges =
816816- opts.exchanges !== undefined ? opts.exchanges : defaultExchanges;
817817-818815 // All exchange are composed into a single one and are called using the constructed client
819816 // and the fallback exchange stream
820820- const composedExchange = composeExchanges(exchanges);
817817+ const composedExchange = composeExchanges(opts.exchanges);
821818822819 // All exchanges receive inputs using which they can forward operations to the next exchange
823820 // and receive a stream of results in return, access the client, or dispatch debugging events
-15
packages/core/src/exchanges/index.ts
···14141515export { mapExchange, mapExchange as errorExchange } from './map';
1616export type { MapExchangeOpts } from './map';
1717-1818-import { cacheExchange } from './cache';
1919-import { dedupExchange } from './dedup';
2020-import { fetchExchange } from './fetch';
2121-2222-/** The default list of exchanges a `Client` falls back to.
2323- *
2424- * @remarks
2525- * When {@link ClientOptions.exchanges} isn’s passed, a {@link Client} is automatically
2626- * created using this list of default exchanges.
2727- *
2828- * By default, this adds deduplication of operations, a basic document cache,
2929- * and the built-in fetch exchange for GraphQL over HTTP.
3030- */
3131-export const defaultExchanges = [dedupExchange, cacheExchange, fetchExchange];