New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fetch-multipart-graphql

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-multipart-graphql

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

  • 3.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

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: 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. For XHR requests, 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.

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.

FAQs

Package last updated on 24 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc