1.7.2 • Published 7 years ago

@lilactown/lokka-transport-http v1.7.2

Weekly downloads
8
License
MIT
Repository
github
Last release
7 years ago

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 @lilactown/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});

Use Custom Agent (Node.js ONLY)

const options = {
  // Necessary only if using the client certificate authentication
  key: fs.readFileSync('client-key.pem'),
  cert: fs.readFileSync('client-cert.pem'),

  // Necessary only if the server uses the self-signed certificate
  ca: [ fs.readFileSync('server-cert.pem') ]
};
const agent = new https.Agent(options);

const transport = new HttpTransport('/graphql', { agent });

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.