Skip to content

Commit

Permalink
remove defaultExchanges
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Mar 13, 2023
1 parent 5bf44bc commit 2ac9b1e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
18 changes: 18 additions & 0 deletions .changeset/calm-buckets-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@urql/core': major
---

Remove `defaultExchanges` from `@urql/core` and make `exchanges` a required property on `Client` construction.
In doing so we make the `urql` package more tree-shakeable as the three default exchanges are in no code paths
meaning they can be removed if not used.

A migration would look as follows if you are currently creating a client without exchanges

```js
import { createClient, dedupExchange, cacheExchange, fetchExchange } from '@urql/core'

const client = createClient({
url: '',
exchanges: [dedupExchange, cacheExchange, fetchExchange]
});
```
13 changes: 5 additions & 8 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {

import { DocumentNode } from 'graphql';

import { composeExchanges, defaultExchanges } from './exchanges';
import { composeExchanges } from './exchanges';
import { fallbackExchange } from './exchanges/fallback';

import {
Expand Down Expand Up @@ -111,13 +111,13 @@ export interface ClientOptions {
* This is the basis for how `urql` handles GraphQL operations, and exchanges handle the creation, execution,
* and control flow of exchanges for the `Client`.
*
* When this option is left out, the `Client` defaults to a list of {@link defaultExchanges}. By default, these
* will implement deduping, caching (via a document cache), and fetching (GraphQL over HTTP).
* To easily get started you should consider using the {@link dedupExchange}, {@link cacheExchange} and {@link fetchExchange}
* these are all exported from the core package.
*
* @see {@link https://formidable.com/open-source/urql/docs/architecture/#the-client-and-exchanges} for more information
* on what `Exchange`s are and how they work.
*/
exchanges?: Exchange[];
exchanges: Exchange[];
/** A configuration flag indicating whether support for "Suspense" is activated.
*
* @remarks
Expand Down Expand Up @@ -813,12 +813,9 @@ export const Client: new (opts: ClientOptions) => Client = function Client(
dispatchDebug = next as ExchangeInput['dispatchDebug'];
}

const exchanges =
opts.exchanges !== undefined ? opts.exchanges : defaultExchanges;

// All exchange are composed into a single one and are called using the constructed client
// and the fallback exchange stream
const composedExchange = composeExchanges(exchanges);
const composedExchange = composeExchanges(opts.exchanges);

// All exchanges receive inputs using which they can forward operations to the next exchange
// and receive a stream of results in return, access the client, or dispatch debugging events
Expand Down
15 changes: 0 additions & 15 deletions packages/core/src/exchanges/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,3 @@ export type {

export { mapExchange, mapExchange as errorExchange } from './map';
export type { MapExchangeOpts } from './map';

import { cacheExchange } from './cache';
import { dedupExchange } from './dedup';
import { fetchExchange } from './fetch';

/** The default list of exchanges a `Client` falls back to.
*
* @remarks
* When {@link ClientOptions.exchanges} isn’s passed, a {@link Client} is automatically
* created using this list of default exchanges.
*
* By default, this adds deduplication of operations, a basic document cache,
* and the built-in fetch exchange for GraphQL over HTTP.
*/
export const defaultExchanges = [dedupExchange, cacheExchange, fetchExchange];

0 comments on commit 2ac9b1e

Please sign in to comment.