Skip to content

Commit

Permalink
Make sure all fetch options are passed (#46)
Browse files Browse the repository at this point in the history
* make sure all fetch options are passed

* updating documentation
  • Loading branch information
santino authored Jul 22, 2022
1 parent 7041587 commit cab5898
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ function fetchQuery(operation, variables) {

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'`.

#### Handling additional request settings

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.
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).

## Browser Support

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.
7 changes: 2 additions & 5 deletions src/fetch.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { PatchResolver } from './PatchResolver';
import { getBoundary } from './getBoundary';

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

0 comments on commit cab5898

Please sign in to comment.