@benzene/http
v0.4.2
Published
Fast, minimal, agnostic GraphQL over HTTP
Downloads
4,325
Maintainers
Readme
@benzene/http
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.