# fetch-multipart-graphql

> Cross browser function to fetch and parse streaming multipart graphql responses.

Latest version **3.3.0** (published 2026-06-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install fetch-multipart-graphql
pnpm add fetch-multipart-graphql
yarn add fetch-multipart-graphql
bun add fetch-multipart-graphql
```

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.3.0 |
| Published | 2026-06-25 |
| First published | 2018-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 42.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 52 |
| Author | Rob Richard |
| Maintainers | robrichard, lilianamatos |

## Links

- npm: https://www.npmjs.com/package/fetch-multipart-graphql
- Repository: https://github.com/relay-tools/fetch-multipart-graphql
- Homepage: https://github.com/relay-tools/fetch-multipart-graphql#readme
- Issues: https://github.com/relay-tools/fetch-multipart-graphql/issues
- npm.io page: https://npm.io/package/fetch-multipart-graphql

## Recent versions

- 3.3.0 (latest) — 2026-06-25
- 2.4.0 (version-2) — 2026-06-29
- 2.0.0-rob.0 (rob) — 2019-10-29
- 2.3.1 — 2025-03-17
- 3.2.2 — 2025-03-17
- 2.3.0 — 2023-04-24
- 3.2.1 — 2023-04-24
- 3.2.0 — 2023-04-24
- 3.1.1 — 2022-10-04
- 3.1.0 — 2022-07-22
- 3.0.0 — 2020-12-10
- 2.2.0 — 2020-11-09
- 2.1.0 — 2020-09-23
- 2.0.1 — 2020-03-10
- 2.0.0 — 2020-03-10
- … 20 more at https://npm.io/package/fetch-multipart-graphql/versions

## README

# fetch-multipart-graphql

Cross-browser function to fetch and parse streaming multipart graphql responses.

This allows you to efficiently fetch streamed GraphQL responses that use the @defer directive as supported by [Apollo Server](https://blog.apollographql.com/introducing-defer-in-apollo-server-f6797c4e9d6e). It can be easily used in a Relay Modern network layer to support deferred queries.

## Usage

In a Relay Network Layer:

```javascript
import fetchMultipart from 'fetch-multipart-graphql';
import { Observable } from 'relay-runtime';

function fetchQuery(operation, variables) {
    return Observable.create(sink => {
        fetchMultipart('/graphql', {
            method: 'POST',
            headers: {
                'content-type': 'application/json',
            },
            body: JSON.stringify({
                query: operation.text,
                variables,
            }),
            credentials: 'same-origin',
            onNext: parts => sink.next(parts),
            onError: err => sink.error(err),
            onComplete: () => sink.complete(),
        });
    });
}
```

#### Handling cookies and other auth headers

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.

---
_Source: https://npm.io/package/fetch-multipart-graphql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
