HTTP Transport Layer for Lokka
Clone or download
Latest commit 54d37f8 Oct 31, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Fix #18. Oct 31, 2016
scripts Add initial version Dec 14, 2015
.babelrc Add initial version Dec 14, 2015
.eslintrc Fix the lint issue. Oct 21, 2016
.gitignore Add initial version Dec 14, 2015
.npmignore Allow ReactNative Support Dec 16, 2015
CHANGELOG.md Update CHANGELOG.md Oct 31, 2016
LICENSE Add initial version Dec 14, 2015
README.md Support custom error handlers Oct 25, 2016
index.js Add initial version Dec 14, 2015
package.json 1.6.1 Oct 31, 2016
yarn.lock Add yarn.lock Oct 21, 2016

README.md

lokka-transport-http

Isomorphic HTTP Transport Layer for Lokka


This is a graphql-express compatible transport layer for Lokka.

Basic Usage

Install the package:

npm i --save lokka-transport-http
npm i --save lokka

This is how to send request to Facebook's SWAPI GraphQL Demo.

import HttpTransport from 'lokka-transport-http';
const transport = new HttpTransport('http://graphql-swapi.parseapp.com/');
transport.send(`
    {
      allFilms {
        films {
          title
        }
      }
    }
`).then(response => {
    console.log(JSON.stringify(response, null, 2));
});

Send Custom Headers

It's possible to send custom headers like this:

const headers = {
    'my-headers': 'some-value'
};
const transport = new HttpTransport('/graphql', {headers});

Authentication

This package does not handle authentication information for you. But it'll let you interact with your app's existing authentication mechanism.

Error Handling

By default it will create and throw a new Error object using the first GraphQL error. Error handling can be customized with the handleErrors option. Check the deafult error handler in lib/index.js for an example.