Skip to content

Commit

Permalink
switch to graphql-helix in ent-graphql-tests since express-graphql do…
Browse files Browse the repository at this point in the history
…esn't seem to be updated anymore :(

graphql/express-graphql#790
graphql/express-graphql#797
  • Loading branch information
lolopinto committed May 20, 2022
1 parent 61ecedf commit 72529ec
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 133 deletions.
104 changes: 24 additions & 80 deletions ts/packages/ent-graphql-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ts/packages/ent-graphql-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
"homepage": "https://github.com/lolopinto/ent#readme",
"dependencies": {
"express": "^4.17.2",
"express-graphql": "^0.12.0",
"graphql-helix": "^1.12.0",
"jest-expect-message": "^1.0.2",
"supertest": "^6.1.6"
},
"devDependencies": {
"@snowtop/ent": "^0.1.0-alpha1",
"@types/express": "^4.17.13",
"@types/jest": "^27.0.3",
"graphql": "^15.3.0",
"graphql": "^16.5.0",
"graphql-upload": "^12.0.0",
"jest": "^27.4.5",
"ts-jest": "^27.1.2",
"typescript": "^4.2.4"
},
"peerDependencies": {
"@snowtop/ent": ">=0.1.0-alpha",
"graphql": "^15.3.0",
"graphql": "^16.5.0",
"jest-expect-message": "^1.0.2"
}
}
37 changes: 23 additions & 14 deletions ts/packages/ent-graphql-tests/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import express, { Express, RequestHandler } from "express";
import { graphqlHTTP } from "express-graphql";
import {
getGraphQLParameters,
processRequest,
ExecutionContext,
sendResult,
} from "graphql-helix";

import { Viewer } from "@snowtop/ent";
import {
GraphQLSchema,
Expand All @@ -13,7 +19,6 @@ import {
GraphQLFieldMap,
} from "graphql";
import { buildContext, registerAuthHandler } from "@snowtop/ent/auth";
import { IncomingMessage, ServerResponse } from "http";
import supertest from "supertest";
import * as fs from "fs";

Expand All @@ -34,19 +39,23 @@ function server(config: queryConfig): Express {
if (config.init) {
config.init(app);
}
app.use(express.json());

let handlers = config.customHandlers || [];
handlers.push(
graphqlHTTP((request: IncomingMessage, response: ServerResponse) => {
const doWork = async () => {
let context = await buildContext(request, response);
return {
schema: config.schema,
context,
};
};
return doWork();
}),
);
handlers.push(async (req, res) => {
const { operationName, query, variables } = getGraphQLParameters(req);
const result = await processRequest({
operationName,
query,
variables,
request: req,
schema: config.schema,
contextFactory: async (executionContext: ExecutionContext) => {
return buildContext(req, res);
},
});
await sendResult(result, res);
});
app.use(config.graphQLPath || "/graphql", ...handlers);

return app;
Expand Down
Loading

0 comments on commit 72529ec

Please sign in to comment.