Skip to content

Commit f2bd01e

Browse files
committed
feat: add support benzene-jit benchmark
1 parent 11979c3 commit f2bd01e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

benchmarks/benzene-jit-http.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"use strict";
2+
3+
const { createServer } = require("http");
4+
const { makeCompileQuery } = require("@benzene/jit");
5+
const { Benzene, makeHandler, parseGraphQLBody } = require("@benzene/http");
6+
const { createApolloSchema } = require("../lib/schemas/createApolloSchema");
7+
8+
const rawBody = (req, done) => {
9+
let body = "";
10+
req.on("data", (chunk) => (body += chunk));
11+
req.on("end", () => done(body));
12+
};
13+
14+
const schema = createApolloSchema();
15+
16+
const GQL = new Benzene({
17+
schema,
18+
compileQuery: makeCompileQuery(),
19+
});
20+
21+
const graphqlHTTP = makeHandler(GQL);
22+
23+
const server = createServer((req, res) => {
24+
rawBody(req, (rawBody) =>
25+
graphqlHTTP({
26+
method: req.method,
27+
headers: req.headers,
28+
body: parseGraphQLBody(rawBody, req.headers["content-type"]),
29+
}).then((result) => {
30+
res.writeHead(result.status, result.headers);
31+
res.end(JSON.stringify(result.payload));
32+
}),
33+
);
34+
});
35+
36+
server.listen(4001);

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"license": "MIT",
2929
"dependencies": {
3030
"@benzene/http": "^0.4.0",
31+
"@benzene/jit": "^0.1.3",
3132
"@graphql-tools/schema": "^8.3.1",
3233
"apollo-opentracing": "^2.1.64",
3334
"apollo-server-express": "^3.5.0",

0 commit comments

Comments
 (0)