JSPM

  • Created
  • Published
  • Downloads 550124
  • Score
    100M100P100Q189661F
  • License MIT

HTTP transport layer for GraphQL

Package Exports

  • apollo-link-http
  • apollo-link-http/lib/httpLink

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (apollo-link-http) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

HTTP Link

Purpose

An Apollo Link to allow sending a single http request per operation.

Installation

npm install apollo-link-http --save

Usage

import HttpLink from "apollo-link-http";

const link = new HttpLink({ uri: "/graphql" });

Options

HTTP Link takes an object with three options on it to customize the behavoir of the link. If your server supports it, the HTTP link can also send over metadata about the request in the extensions field. To enable this, pass includeExtensions as true

name value default required
uri string "/graphql" false
includeExtensions boolean false false
fetch ApolloFetch ApolloFetch false

By default, this link uses the Apollo Fetch library for the HTTP transport.

Context

The HTTP Link uses the headers field on the context to allow passing headers to the HTTP request.

name value default required
headers Headers (or object) {} false
import HttpLink from "apollo-link-http";
import ApolloClient from "apollo-client";
import InMemoryCache from "apollo-cache-inmemory";

const client = new ApolloClient({
  link: new HttpLink({ uri: "/graphql" }),
  cache: new InMemoryCache()
});

// a query with apollo-client
client.query({
  query: MY_QUERY,
  context: {
    // example of setting the headers with context per operation
    headers: {
      authoriztion: Meteor.userId()
    }
  }
})