Skip to content

Commit cab5898

Browse files
authored
Make sure all fetch options are passed (#46)
* make sure all fetch options are passed * updating documentation
1 parent 7041587 commit cab5898

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ function fetchQuery(operation, variables) {
3636

3737
The `credentials` param is passed to [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters). For XHR requests, [`XMLHttpRequest.withCredentials`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials) is mapped to true when `credentials: 'include'`.
3838

39+
#### Handling additional request settings
40+
41+
When `fetch` is not available requests are sent through XHR, which supports standard `method`, `headers`, `credentials` and `body` settings; as seen in the code example above.
42+
When requests are sent through `fetch` we can also set, in addition to the properties already mentioned, all the [options supported by fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options).
43+
3944
## Browser Support
4045

4146
Tested in the latest Chrome, Firefox, Safari, Edge, and Internet Explorer 11. Requires a polyfill for TextEncoder/Decoder. Since only utf-8 encoding is required, it's recommended to use [text-encoding-utf-8](https://www.npmjs.com/package/text-encoding-utf-8) to minimize impact on bundle size.

src/fetch.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { PatchResolver } from './PatchResolver';
22
import { getBoundary } from './getBoundary';
33

4-
export function fetchImpl(
5-
url,
6-
{ method, headers, credentials, body, onNext, onError, onComplete }
7-
) {
8-
return fetch(url, { method, headers, body, credentials })
4+
export function fetchImpl(url, { onNext, onComplete, onError, ...fetchOptions }) {
5+
return fetch(url, fetchOptions)
96
.then((response) => {
107
const contentType = (!!response.headers && response.headers.get('Content-Type')) || '';
118
// @defer uses multipart responses to stream patches over HTTP

0 commit comments

Comments
 (0)