Lokka HTTP Transport

1.6.1 · abandoned · verified Wed Apr 22

Lokka-transport-http provides an isomorphic HTTP transport layer designed for the Lokka GraphQL client. It facilitates sending GraphQL queries over HTTP to `graphql-express` compatible endpoints. The package's current stable version is 1.6.1, with its last release approximately 9 years ago. It supports sending custom HTTP headers and integrates with existing cookie-based authentication mechanisms, or allows for explicit `Authorization` header configuration. A key differentiator is its minimalist approach as a transport layer, allowing Lokka (a simple GraphQL client itself) to focus on query construction. The package, and the broader Lokka ecosystem, appears to be unmaintained, with no recent updates or active development. This means no new features, bug fixes, or security patches are likely. By default, it throws an error on the first GraphQL error returned by the server, but this behavior can be customized.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `lokka-transport-http` with Lokka to query a GraphQL endpoint, including an example of sending custom headers for authentication.

import HttpTransport from 'lokka-transport-http';
import Lokka from 'lokka';

// Initialize Lokka with the HTTP transport
const client = new Lokka({
  transport: new HttpTransport('http://graphql-swapi.parseapp.com/')
});

// Send a simple GraphQL query
client.query(`
    {
      allFilms {
        films {
          title
        }
      }
    }
`).then(response => {
    console.log('Query successful:', JSON.stringify(response, null, 2));
}).catch(error => {
    console.error('Query failed:', error);
});

// Example with custom headers (e.g., for authentication)
const headers = {
    'Authorization': `Bearer ${process.env.AUTH_TOKEN ?? ''}`,
    'x-custom-header': 'some-value'
};
const authenticatedClient = new Lokka({
    transport: new HttpTransport('http://your-authenticated-graphql-endpoint.com/graphql', { headers })
});

authenticatedClient.query(`{ viewer { id } }`)
  .then(response => console.log('Authenticated query:', response))
  .catch(error => console.error('Authenticated query failed:', error));

view raw JSON →