@grafoo/http-transport
TypeScript icon, indicating that this package has built-in type declarations

1.4.2 • Public • Published

@grafoo/http-transport

A Simple HTTP Client for GraphQL Servers

build coverage npm downloads size code style: prettier mantained with: lerna slack

Install

$ npm i @grafoo/http-transport

Usage

@grafoo/http-transport default export is a factory that accepts as arguments uri and fetchOptions (that can be an object or a function):

import createTransport from "@grafoo/http-transport";

const request = createTransport("http://some.graphql.api", () => ({
  headers: {
    authorization: storage.getItem("authorization")
  }
}));

const USER_QUERY = `
  query($id: ID!) {
    user(id: $id) {
      name
    }
  }
`;

const variables = { id: 123 };

request(USER_QUERY, variables).then(({ data }) => {
  console.log(data.user);
});

Warning

As this package uses fetch and Object.assign under the hood, make sure to install the proper polyfills if you want to use it in your project.

LICENSE

MIT

Package Sidebar

Install

npm i @grafoo/http-transport

Weekly Downloads

1

Version

1.4.2

License

MIT

Unpacked Size

5.83 kB

Total Files

8

Last publish

Collaborators

  • grafoo