0.4.2 • Published 2 years ago

@benzene/http v0.4.2

Weekly downloads
9
License
MIT
Repository
github
Last release
2 years ago

@benzene/http

npm CI codecov PRs Welcome

Fast and simple framework-agnostic GraphQL HTTP Server

Installation

npm i graphql @benzene/http

Usage

import { createServer } from "http";
import { Benzene, makeHandler, parseGraphQLBody } from "@benzene/http";

function readBody(request) {
  return new Promise((resolve) => {
    let body = "";
    request.on("data", (chunk) => (body += chunk));
    request.on("end", () => resolve(body));
  });
}

const GQL = new Benzene({ schema });

const graphqlHTTP = makeHandler(GQL, options);

createServer(async (req, res) => {
  const rawBody = await readBody(req);
  const result = await graphqlHTTP({
    method: req.method,
    headers: req.headers,
    body: parseGraphQLBody(rawBody, req.headers["content-type"]),
  });
  res.writeHead(result.status, result.headers);
  res.end(JSON.stringify(result.payload));
}).listen(3000);

Documentation

Documentation is available at benzene.vercel.app. Check out examples for integrations with different server libraries and tools.

0.4.2

2 years ago

0.4.1

2 years ago

0.3.0

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.2.0

3 years ago

0.2.0-next.1

3 years ago

0.2.0-next.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago