You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/exchanges.md
+45-9Lines changed: 45 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,19 +4,23 @@ Exchanges are the mechanism by which `reason-urql` modifies requests before they
4
4
5
5
The `Exchanges``module` is a submodule of the `Client` module and can be referenced at `ReasonUrql.Client.Exchanges`. The following exchanges are provided out of the box with `reason-urql`.
6
6
7
-
#### `cacheExchange`
7
+
## Core Exchanges
8
+
9
+
`urql` ships with a set of core exchanges that are baked right into `@urql/core` and can be referenced safely in `reason-urql` without installing any additional packages. These are detailed below.
10
+
11
+
### `cacheExchange`
8
12
9
13
The `cacheExchange` provides basic caching support for your GraphQL operations. It is of type `Exchanges.t`.
10
14
11
-
####`dedupExchange`
15
+
### `dedupExchange`
12
16
13
17
The `dedupExchange` will deduplicate pending operations waiting for a response. For example, if a user attempts to execute the same query by clicking a button in rapid succession, the `dedupExchange` will filter these events to a single request. It is of type `Exchanges.t`.
14
18
15
-
####`fetchExchange`
19
+
### `fetchExchange`
16
20
17
21
The `fetchExchange` is responsible for actually sending your request to your GraphQL API and handling the response. It is of type `Exchanges.t`.
18
22
19
-
####`defaultExchanges`
23
+
### `defaultExchanges`
20
24
21
25
The above three exchanges make up `urql`'s `defaultExchanges`. When you create a client in `reason-urql` these exchanges are already applied by default. If you specify an `exchanges` array, be sure to include the specific exchanges you need. You almost always want the `defaultExchanges`, so make sure to include them using `Array.concat` or `Array.append`.
22
26
@@ -37,11 +41,11 @@ let client = Client.(
37
41
);
38
42
```
39
43
40
-
####`debugExchange`
44
+
### `debugExchange`
41
45
42
46
The `debugExchange` is useful for tracking how operations are passing through the exchanges pipeline. It simply logs all incoming and outgoing operations to the console. Be sure to remove this in production! It is of type `Exchanges.t`.
43
47
44
-
####`subscriptionExchange`
48
+
### `subscriptionExchange`
45
49
46
50
The `subscriptionExchange` should be used in the event that you intend to support GraphQL subscriptions in your application through use of `useSubscription` or the client's `executeSubscription` method.
47
51
@@ -79,7 +83,7 @@ let client = Client.(
79
83
);
80
84
```
81
85
82
-
####`ssrExchange`
86
+
### `ssrExchange`
83
87
84
88
The `ssrExchange` accepts a single optional argument, `~ssrExchangeParams`, a record with two fields:
85
89
@@ -133,11 +137,43 @@ let extractedData = Client.Exchanges.restoreData(~exchange=ssrCache, ~restore=ur
133
137
134
138
This part of the API is still quite experimental, as server-side rendering in Reason with Next.js is still in its infancy. Use with caution. For more information, read `urql`'s server-side rendering guide [here](https://github.com/FormidableLabs/urql/blob/master/docs/basics.md#server-side-rendering). To see an example of server-side rendering with `reason-urql`, check out our [`reason-urql-ssr` example](https://github.com/parkerziegler/reason-urql-ssr).
135
139
136
-
####`composeExchanges`
140
+
### `composeExchanges`
137
141
138
142
`composeExchanges` is a helper function that will compose a single exchange function from an array of exchanges. Operations will be run through the provided exchanges in the order that they were provided to `composeExchanges`.
139
143
140
-
### Custom Exchanges
144
+
## Ecosystem Exchanges
145
+
146
+
In addition to the core exchanges exposed by `@urql/core`, `urql` also supports more abstracted exchanges that meet particular needs that may or may not be critical to your use case. In contrast to the core exchanges, these ecosystem exchanges should be used when you have a specific use case that warrants them. Many of these exchanges require additional packages to be installed. `reason-urql` is in the process of adding bindings for these exchanges; if the ecosystem exchange you're interested in isn't outlined below, the bindings may not have yet been implemented. Community contributions are very welcome in this space!
147
+
148
+
### `multipartFetchExchange`
149
+
150
+
The `multipartFetchExchange` builds on the `fetchExchange` but adds additional functionality for multipart file uploads. It should replace the use of the `fetchExchange` if you need to support traditional fetches and multipart file uploads.
151
+
152
+
To use the `multipartFetchExchange`, add the package to your dependencies:
153
+
154
+
```sh
155
+
yarn add @urql/exchange-multipart-fetch
156
+
```
157
+
158
+
Then, substitute the `fetchExchange` with the `multipartFetchExchange`:
159
+
160
+
```res
161
+
open ReasonUrql
162
+
163
+
let client = Client.make(
164
+
~url="http://localhost:3000",
165
+
~exchanges=[|
166
+
Client.Exchanges.dedupExchange,
167
+
Client.Exchanges.cacheExchange,
168
+
Client.Exchanges.multipartFetchExchange
169
+
|],
170
+
()
171
+
)
172
+
```
173
+
174
+
Read more on the `multipartFetchExchange`[here](https://github.com/FormidableLabs/urql/tree/main/exchanges/multipart-fetch).
175
+
176
+
## Custom Exchanges
141
177
142
178
`reason-urql` also allows you to write your own exchanges to modify outgoing GraphQL requests and incoming responses. To read up on the basics of exchanges, check out the excellent [`urql` documentation](https://formidable.com/open-source/urql/docs/concepts/exchanges/).
0 commit comments