Skip to content

Commit 72529ec

Browse files
committed
switch to graphql-helix in ent-graphql-tests since express-graphql doesn't seem to be updated anymore :(
graphql/express-graphql#790 graphql/express-graphql#797
1 parent 61ecedf commit 72529ec

File tree

4 files changed

+96
-133
lines changed

4 files changed

+96
-133
lines changed

ts/packages/ent-graphql-tests/package-lock.json

Lines changed: 24 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts/packages/ent-graphql-tests/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@
3030
"homepage": "https://github.com/lolopinto/ent#readme",
3131
"dependencies": {
3232
"express": "^4.17.2",
33-
"express-graphql": "^0.12.0",
33+
"graphql-helix": "^1.12.0",
3434
"jest-expect-message": "^1.0.2",
3535
"supertest": "^6.1.6"
3636
},
3737
"devDependencies": {
3838
"@snowtop/ent": "^0.1.0-alpha1",
3939
"@types/express": "^4.17.13",
4040
"@types/jest": "^27.0.3",
41-
"graphql": "^15.3.0",
41+
"graphql": "^16.5.0",
4242
"graphql-upload": "^12.0.0",
4343
"jest": "^27.4.5",
4444
"ts-jest": "^27.1.2",
4545
"typescript": "^4.2.4"
4646
},
4747
"peerDependencies": {
4848
"@snowtop/ent": ">=0.1.0-alpha",
49-
"graphql": "^15.3.0",
49+
"graphql": "^16.5.0",
5050
"jest-expect-message": "^1.0.2"
5151
}
5252
}

ts/packages/ent-graphql-tests/src/index.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import express, { Express, RequestHandler } from "express";
2-
import { graphqlHTTP } from "express-graphql";
2+
import {
3+
getGraphQLParameters,
4+
processRequest,
5+
ExecutionContext,
6+
sendResult,
7+
} from "graphql-helix";
8+
39
import { Viewer } from "@snowtop/ent";
410
import {
511
GraphQLSchema,
@@ -13,7 +19,6 @@ import {
1319
GraphQLFieldMap,
1420
} from "graphql";
1521
import { buildContext, registerAuthHandler } from "@snowtop/ent/auth";
16-
import { IncomingMessage, ServerResponse } from "http";
1722
import supertest from "supertest";
1823
import * as fs from "fs";
1924

@@ -34,19 +39,23 @@ function server(config: queryConfig): Express {
3439
if (config.init) {
3540
config.init(app);
3641
}
42+
app.use(express.json());
43+
3744
let handlers = config.customHandlers || [];
38-
handlers.push(
39-
graphqlHTTP((request: IncomingMessage, response: ServerResponse) => {
40-
const doWork = async () => {
41-
let context = await buildContext(request, response);
42-
return {
43-
schema: config.schema,
44-
context,
45-
};
46-
};
47-
return doWork();
48-
}),
49-
);
45+
handlers.push(async (req, res) => {
46+
const { operationName, query, variables } = getGraphQLParameters(req);
47+
const result = await processRequest({
48+
operationName,
49+
query,
50+
variables,
51+
request: req,
52+
schema: config.schema,
53+
contextFactory: async (executionContext: ExecutionContext) => {
54+
return buildContext(req, res);
55+
},
56+
});
57+
await sendResult(result, res);
58+
});
5059
app.use(config.graphQLPath || "/graphql", ...handlers);
5160

5261
return app;

0 commit comments

Comments
 (0)