diff --git a/ts/packages/ent-graphql-tests/package-lock.json b/ts/packages/ent-graphql-tests/package-lock.json index 468a1e72d..5e4c74b30 100644 --- a/ts/packages/ent-graphql-tests/package-lock.json +++ b/ts/packages/ent-graphql-tests/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "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" }, @@ -18,7 +18,7 @@ "@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", @@ -26,7 +26,7 @@ }, "peerDependencies": { "@snowtop/ent": ">=0.1.0-alpha", - "graphql": "^15.3.0", + "graphql": "^16.5.0", "jest-expect-message": "^1.0.2" } }, @@ -2612,38 +2612,6 @@ "node": ">= 0.10.0" } }, - "node_modules/express-graphql": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/express-graphql/-/express-graphql-0.12.0.tgz", - "integrity": "sha512-DwYaJQy0amdy3pgNtiTDuGGM2BLdj+YO2SgbKoLliCfuHv3VVTt7vNG/ZqK2hRYjtYHE2t2KB705EU94mE64zg==", - "dependencies": { - "accepts": "^1.3.7", - "content-type": "^1.0.4", - "http-errors": "1.8.0", - "raw-body": "^2.4.1" - }, - "engines": { - "node": ">= 10.x" - }, - "peerDependencies": { - "graphql": "^14.7.0 || ^15.3.0" - } - }, - "node_modules/express-graphql/node_modules/http-errors": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.0.tgz", - "integrity": "sha512-4I8r0C5JDhT5VkvI47QktDW75rNlGVsUf/8hzjCC/wkWI/jdTRmBb9aI7erSG82r1bjKY3F6k28WnsVxB1C73A==", - "dependencies": { - "depd": "~1.1.2", - "inherits": "2.0.4", - "setprototypeof": "1.2.0", - "statuses": ">= 1.5.0 < 2", - "toidentifier": "1.0.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/express/node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -2992,11 +2960,19 @@ "dev": true }, "node_modules/graphql": { - "version": "15.5.3", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.5.3.tgz", - "integrity": "sha512-sM+jXaO5KinTui6lbK/7b7H/Knj9BpjGxZ+Ki35v7YbUJxxdBCUqNM0h3CRVU1ZF9t5lNiBzvBCSYPvIwxPOQA==", + "version": "16.5.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.5.0.tgz", + "integrity": "sha512-qbHgh8Ix+j/qY+a/ZcJnFQ+j8ezakqPiHwPiZhV/3PgGlgf96QMBB5/f2rkiC9sgLoy/xvT6TSiaf2nTHJh5iA==", "engines": { - "node": ">= 10.x" + "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" + } + }, + "node_modules/graphql-helix": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/graphql-helix/-/graphql-helix-1.12.0.tgz", + "integrity": "sha512-wTu1m/ZFBCgzLPCg/dHO4cNy9JR5Sq/3RqDVblqrU3b/Yem7EXZtQMzG045tHqkCdbgcgQl+kIkXDur1yLfdtw==", + "peerDependencies": { + "graphql": "^15.3.0 || ^16.0.0" } }, "node_modules/graphql-upload": { @@ -5900,14 +5876,6 @@ "node": ">=8.0" } }, - "node_modules/toidentifier": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", - "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==", - "engines": { - "node": ">=0.6" - } - }, "node_modules/tough-cookie": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz", @@ -8580,31 +8548,6 @@ } } }, - "express-graphql": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/express-graphql/-/express-graphql-0.12.0.tgz", - "integrity": "sha512-DwYaJQy0amdy3pgNtiTDuGGM2BLdj+YO2SgbKoLliCfuHv3VVTt7vNG/ZqK2hRYjtYHE2t2KB705EU94mE64zg==", - "requires": { - "accepts": "^1.3.7", - "content-type": "^1.0.4", - "http-errors": "1.8.0", - "raw-body": "^2.4.1" - }, - "dependencies": { - "http-errors": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.0.tgz", - "integrity": "sha512-4I8r0C5JDhT5VkvI47QktDW75rNlGVsUf/8hzjCC/wkWI/jdTRmBb9aI7erSG82r1bjKY3F6k28WnsVxB1C73A==", - "requires": { - "depd": "~1.1.2", - "inherits": "2.0.4", - "setprototypeof": "1.2.0", - "statuses": ">= 1.5.0 < 2", - "toidentifier": "1.0.0" - } - } - } - }, "ext": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/ext/-/ext-1.5.0.tgz", @@ -8871,9 +8814,15 @@ "dev": true }, "graphql": { - "version": "15.5.3", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.5.3.tgz", - "integrity": "sha512-sM+jXaO5KinTui6lbK/7b7H/Knj9BpjGxZ+Ki35v7YbUJxxdBCUqNM0h3CRVU1ZF9t5lNiBzvBCSYPvIwxPOQA==" + "version": "16.5.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.5.0.tgz", + "integrity": "sha512-qbHgh8Ix+j/qY+a/ZcJnFQ+j8ezakqPiHwPiZhV/3PgGlgf96QMBB5/f2rkiC9sgLoy/xvT6TSiaf2nTHJh5iA==" + }, + "graphql-helix": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/graphql-helix/-/graphql-helix-1.12.0.tgz", + "integrity": "sha512-wTu1m/ZFBCgzLPCg/dHO4cNy9JR5Sq/3RqDVblqrU3b/Yem7EXZtQMzG045tHqkCdbgcgQl+kIkXDur1yLfdtw==", + "requires": {} }, "graphql-upload": { "version": "12.0.0", @@ -11122,11 +11071,6 @@ "is-number": "^7.0.0" } }, - "toidentifier": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", - "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" - }, "tough-cookie": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz", diff --git a/ts/packages/ent-graphql-tests/package.json b/ts/packages/ent-graphql-tests/package.json index ad9ace2ef..639a9c827 100644 --- a/ts/packages/ent-graphql-tests/package.json +++ b/ts/packages/ent-graphql-tests/package.json @@ -30,7 +30,7 @@ "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" }, @@ -38,7 +38,7 @@ "@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", @@ -46,7 +46,7 @@ }, "peerDependencies": { "@snowtop/ent": ">=0.1.0-alpha", - "graphql": "^15.3.0", + "graphql": "^16.5.0", "jest-expect-message": "^1.0.2" } } diff --git a/ts/packages/ent-graphql-tests/src/index.ts b/ts/packages/ent-graphql-tests/src/index.ts index 552ead834..532612a7c 100644 --- a/ts/packages/ent-graphql-tests/src/index.ts +++ b/ts/packages/ent-graphql-tests/src/index.ts @@ -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, @@ -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"; @@ -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; diff --git a/ts/packages/ent-graphql-tests/src/test.ts b/ts/packages/ent-graphql-tests/src/test.ts index 0d7ca9a65..9f9d958c3 100644 --- a/ts/packages/ent-graphql-tests/src/test.ts +++ b/ts/packages/ent-graphql-tests/src/test.ts @@ -11,8 +11,6 @@ import { } from "graphql"; import { GraphQLUpload, graphqlUploadExpress } from "graphql-upload"; import * as fs from "fs"; -import { graphqlHTTP } from "express-graphql"; -import { IncomingMessage, ServerResponse } from "http"; import supertest from "supertest"; import { @@ -24,6 +22,11 @@ import { import { GraphQLNodeInterface } from "@snowtop/ent/graphql"; import { buildContext } from "@snowtop/ent/auth"; +import { + getGraphQLParameters, + processRequest, + sendResult, +} from "graphql-helix"; test("simplest query", async () => { let schema = new GraphQLSchema({ @@ -44,6 +47,7 @@ test("simplest query", async () => { schema: schema, args: {}, root: "hello", + // debugMode: true, }; // root query @@ -156,19 +160,19 @@ let addressType = new GraphQLObjectType({ name: "Address", fields: { id: { - type: GraphQLNonNull(GraphQLID), + type: new GraphQLNonNull(GraphQLID), }, street: { - type: GraphQLNonNull(GraphQLString), + type: new GraphQLNonNull(GraphQLString), }, city: { - type: GraphQLNonNull(GraphQLString), + type: new GraphQLNonNull(GraphQLString), }, state: { - type: GraphQLNonNull(GraphQLString), + type: new GraphQLNonNull(GraphQLString), }, zipCode: { - type: GraphQLNonNull(GraphQLString), + type: new GraphQLNonNull(GraphQLString), }, apartment: { type: GraphQLString, @@ -181,7 +185,7 @@ let contactType = new GraphQLObjectType({ name: "ContactType", fields: { id: { - type: GraphQLNonNull(GraphQLID), + type: new GraphQLNonNull(GraphQLID), }, firstName: { type: GraphQLString, @@ -203,7 +207,7 @@ let userType = new GraphQLObjectType({ name: "User", fields: { id: { - type: GraphQLNonNull(GraphQLID), + type: new GraphQLNonNull(GraphQLID), }, firstName: { type: GraphQLString, @@ -215,15 +219,15 @@ let userType = new GraphQLObjectType({ type: addressType, }, contacts: { - type: GraphQLList(contactType), + type: new GraphQLList(contactType), args: { first: { - type: GraphQLNonNull(GraphQLInt), + type: new GraphQLNonNull(GraphQLInt), }, }, }, nicknames: { - type: GraphQLList(GraphQLNonNull(GraphQLString)), + type: new GraphQLList(new GraphQLNonNull(GraphQLString)), }, }, interfaces: [GraphQLNodeInterface], @@ -237,7 +241,7 @@ let viewerType = new GraphQLObjectType({ name: "Viewer", fields: { user: { - type: GraphQLNonNull(userType), + type: new GraphQLNonNull(userType), }, }, }); @@ -248,7 +252,7 @@ let rootQuery = new GraphQLObjectType({ user: { args: { id: { - type: GraphQLNonNull(GraphQLID), + type: new GraphQLNonNull(GraphQLID), }, }, type: userType, @@ -367,7 +371,7 @@ test("mutation with args", async () => { userEdit: { args: { id: { - type: GraphQLNonNull(GraphQLID), + type: new GraphQLNonNull(GraphQLID), }, firstName: { type: GraphQLString, @@ -620,10 +624,12 @@ test("nullQueryPaths with nullable list contents", async () => { users: { args: { ids: { - type: GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLID))), + type: new GraphQLNonNull( + new GraphQLList(new GraphQLNonNull(GraphQLID)), + ), }, }, - type: GraphQLNonNull(GraphQLList(userType)), + type: new GraphQLNonNull(new GraphQLList(userType)), resolve(_source, { ids }) { let ret: (User | null)[] = []; for (const id of ids) { @@ -739,7 +745,7 @@ describe("inline fragments", () => { node: { args: { id: { - type: GraphQLNonNull(GraphQLID), + type: new GraphQLNonNull(GraphQLID), }, }, type: GraphQLNodeInterface, @@ -864,10 +870,10 @@ describe("file upload", () => { name: "RootMutationType", fields: { fileUpload: { - type: GraphQLNonNull(GraphQLBoolean), + type: new GraphQLNonNull(GraphQLBoolean), args: { file: { - type: GraphQLNonNull(GraphQLUpload), + type: new GraphQLNonNull(GraphQLUpload), }, }, async resolve(src, args) { @@ -882,10 +888,12 @@ describe("file upload", () => { }, }, fileUploadMultiple: { - type: GraphQLNonNull(GraphQLBoolean), + type: new GraphQLNonNull(GraphQLBoolean), args: { files: { - type: GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLUpload))), + type: new GraphQLNonNull( + new GraphQLList(new GraphQLNonNull(GraphQLUpload)), + ), }, }, async resolve(src, args) { @@ -1014,7 +1022,7 @@ test("false boolean", async () => { userEdit: { args: { id: { - type: GraphQLNonNull(GraphQLID), + type: new GraphQLNonNull(GraphQLID), }, firstName: { type: GraphQLString, @@ -1072,19 +1080,21 @@ test("custom server", async () => { }); const app = express(); - app.use( - "/custom_graphql", - graphqlHTTP((request: IncomingMessage, response: ServerResponse) => { - let doWork = async () => { - let context = await buildContext(request, response); - return { - schema: schema, - context, - }; - }; - return doWork(); - }), - ); + app.use(express.json()); + app.use("/custom_graphql", async (req, res) => { + const { operationName, query, variables } = getGraphQLParameters(req); + const result = await processRequest({ + operationName, + query, + variables, + request: req, + schema, + contextFactory: async () => { + return buildContext(req, res); + }, + }); + await sendResult(result, res); + }); app.use("/hello", async (req, res) => res.json({ world: true }));