3.2.1 • Published 1 year ago

fetch-multipart-graphql v3.2.1

Weekly downloads
208
License
MIT
Repository
github
Last release
1 year ago

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. It can be easily used in a Relay Modern network layer to support deferred queries.

Usage

In a Relay Network Layer:

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: json => sink.next(json),
            onError: err => sink.error(err),
            onComplete: () => sink.complete(),
        });
    });
}

Handling cookies and other auth headers

The credentials param is passed to fetch. For XHR requests, XMLHttpRequest.withCredentials is mapped to true when credentials: 'include'.

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 to minimize impact on bundle size.

2.3.0

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

3 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.0

4 years ago

2.0.0-rob.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.1.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago