Skip to content

Commit a40c8de

Browse files
committed
build: replace express-graphql with graphql-http and graphql-playground-middleware-express
toward resolution of issue cypress-io#1420 and cypress-io#1508
1 parent d6f7f39 commit a40c8de

File tree

8 files changed

+60
-56
lines changed

8 files changed

+60
-56
lines changed

Diff for: backend/app.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import session from "express-session";
66
import bodyParser from "body-parser";
77
import cors from "cors";
88
import paginate from "express-paginate";
9-
import { graphqlHTTP } from "express-graphql";
9+
import { createHandler } from "graphql-http/lib/use/express";
1010
import { loadSchemaSync } from "@graphql-tools/load";
1111
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
1212
import { addResolversToSchema } from "@graphql-tools/schema";
@@ -15,6 +15,7 @@ import auth from "./auth";
1515
import userRoutes from "./user-routes";
1616
import contactRoutes from "./contact-routes";
1717
import bankAccountRoutes from "./bankaccount-routes";
18+
import gqlPlaygroundRoutes from "./gql-playground-routes";
1819
import transactionRoutes from "./transaction-routes";
1920
import likeRoutes from "./like-routes";
2021
import commentRoutes from "./comment-routes";
@@ -96,12 +97,14 @@ if (process.env.VITE_GOOGLE) {
9697

9798
app.use(
9899
"/graphql",
99-
graphqlHTTP({
100+
createHandler({
100101
schema: schemaWithResolvers,
101-
graphiql: true,
102+
context: async (req, _args) => {
103+
return { user: req.raw.user };
104+
},
102105
})
103106
);
104-
107+
app.use("/gql-playground", gqlPlaygroundRoutes);
105108
app.use("/users", userRoutes);
106109
app.use("/contacts", contactRoutes);
107110
app.use("/bankAccounts", bankAccountRoutes);

Diff for: backend/gql-playground-routes.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import express from "express";
2+
import expressPlayground from "graphql-playground-middleware-express";
3+
4+
const router = express.Router();
5+
router.get("/", expressPlayground({ endpoint: "/graphql" }));
6+
export default router;

Diff for: backend/graphql/resolvers/Mutation.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { createBankAccountForUser, removeBankAccountById } from "../../database";
22

33
const Mutation = {
4-
createBankAccount: (obj: any, args: any, ctx: any) => {
5-
const account = createBankAccountForUser(ctx.user.id!, args);
6-
return account;
4+
createBankAccount: (obj: any, args: any, ctx: { user: { id: string } }) => {
5+
return createBankAccountForUser(ctx.user.id, args);
76
},
87
deleteBankAccount: (obj: any, args: any, ctx: any) => {
98
removeBankAccountById(args.id);

Diff for: backend/graphql/resolvers/Query.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { getBankAccountsByUserId } from "../../database";
22

33
const Query = {
4-
listBankAccount(obj: any, args: any, ctx: any) {
4+
listBankAccount(obj: any, args: any, ctx: { user: { id: string } }) {
55
/* istanbul ignore next */
66
try {
7-
const accounts = getBankAccountsByUserId(ctx.user.id!);
8-
9-
return accounts;
7+
return getBankAccountsByUserId(ctx.user.id);
108
/* istanbul ignore next */
119
} catch (err: any) {
1210
/* istanbul ignore next */

Diff for: cypress/tests/api/api-bankaccounts.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe("Bank Accounts API", function () {
101101
}`,
102102
}).then((response) => {
103103
expect(response.status).to.eq(200);
104+
expect(JSON.stringify(response.body.errors || "notThere")).to.eq('"notThere"');
104105
expect(response.body.data.listBankAccount[0].userId).to.eq(userId);
105106
});
106107
});

Diff for: data/database.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
{
44
"id": "t45AiwidW",
55
"uuid": "6383f84e-b511-44c5-a835-3ece1d781fa8",
6-
"firstName": "Edgar",
7-
"lastName": "Johns",
6+
"firstName": "New First Name",
7+
"lastName": "New Last Name",
88
"username": "Katharina_Bernier",
99
"password": "$2a$10$5PXHGtcsckWtAprT5/JmluhR13f16BL8SIGhvAKNP.Dhxkt69FfzW",
10-
"email": "Norene39@yahoo.com",
11-
"phoneNumber": "625-316-9882",
10+
"email": "email@email.com",
11+
"phoneNumber": "6155551212",
1212
"avatar": "https://cypress-realworld-app-svgs.s3.amazonaws.com/t45AiwidW.svg",
1313
"defaultPrivacyLevel": "public",
1414
"balance": 168137,

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@
103103
"eslint-plugin-cypress": "2.15.1",
104104
"eslint-plugin-prettier": "^5.0.0",
105105
"express": "4.18.3",
106-
"express-graphql": "0.12.0",
107106
"express-jwt": "6.1.2",
108107
"express-paginate": "1.0.2",
109108
"express-session": "1.18.0",
110109
"express-validator": "6.15.0",
111110
"fuse.js": "6.5.3",
112111
"graphql": "16.8.1",
112+
"graphql-http": "^1.22.0",
113+
"graphql-playground-middleware-express": "^1.7.23",
113114
"graphql-tools": "8.2.7",
114115
"http-proxy-middleware": "0.19.1",
115116
"husky": "7.0.4",

Diff for: yarn.lock

+36-40
Original file line numberDiff line numberDiff line change
@@ -4429,7 +4429,7 @@ abort-controller@^3.0.0:
44294429
dependencies:
44304430
event-target-shim "^5.0.0"
44314431

4432-
accepts@^1.3.7, accepts@~1.3.8:
4432+
accepts@~1.3.8:
44334433
version "1.3.8"
44344434
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e"
44354435
integrity sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==
@@ -5498,7 +5498,7 @@ combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
54985498
dependencies:
54995499
delayed-stream "~1.0.0"
55005500

5501-
commander@^2.20.0:
5501+
commander@^2.20.0, commander@^2.20.3:
55025502
version "2.20.3"
55035503
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
55045504
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
@@ -5574,7 +5574,7 @@ [email protected], content-disposition@^0.5.4:
55745574
dependencies:
55755575
safe-buffer "5.2.1"
55765576

5577-
content-type@^1.0.4, content-type@~1.0.4, content-type@~1.0.5:
5577+
content-type@~1.0.4, content-type@~1.0.5:
55785578
version "1.0.5"
55795579
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918"
55805580
integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==
@@ -5711,6 +5711,11 @@ cssesc@^3.0.0:
57115711
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee"
57125712
integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==
57135713

5714+
5715+
version "0.0.10"
5716+
resolved "https://registry.yarnpkg.com/cssfilter/-/cssfilter-0.0.10.tgz#c6d2672632a2e5c83e013e6864a42ce8defd20ae"
5717+
integrity sha512-FAaLDaplstoRsDR8XGYH51znUN0UY7nMc6Z9/fvE8EXGwvJE9hu7W2vHwx1+bd6gCYnln9nLbzxFTrcO9YQDZw==
5718+
57145719
cssstyle@^3.0.0:
57155720
version "3.0.0"
57165721
resolved "https://registry.yarnpkg.com/cssstyle/-/cssstyle-3.0.0.tgz#17ca9c87d26eac764bb8cfd00583cff21ce0277a"
@@ -5978,11 +5983,6 @@ [email protected], depd@^2.0.0, depd@~2.0.0:
59785983
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"
59795984
integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==
59805985

5981-
depd@~1.1.2:
5982-
version "1.1.2"
5983-
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9"
5984-
integrity sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==
5985-
59865986
dequal@^2.0.3:
59875987
version "2.0.3"
59885988
resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.3.tgz#2644214f1997d39ed0ee0ece72335490a7ac67be"
@@ -6716,16 +6716,6 @@ exponential-backoff@^3.1.1:
67166716
resolved "https://registry.yarnpkg.com/exponential-backoff/-/exponential-backoff-3.1.1.tgz#64ac7526fe341ab18a39016cd22c787d01e00bf6"
67176717
integrity sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==
67186718

6719-
6720-
version "0.12.0"
6721-
resolved "https://registry.yarnpkg.com/express-graphql/-/express-graphql-0.12.0.tgz#58deabc309909ca2c9fe2f83f5fbe94429aa23df"
6722-
integrity sha512-DwYaJQy0amdy3pgNtiTDuGGM2BLdj+YO2SgbKoLliCfuHv3VVTt7vNG/ZqK2hRYjtYHE2t2KB705EU94mE64zg==
6723-
dependencies:
6724-
accepts "^1.3.7"
6725-
content-type "^1.0.4"
6726-
http-errors "1.8.0"
6727-
raw-body "^2.4.1"
6728-
67296719
67306720
version "6.1.2"
67316721
resolved "https://registry.yarnpkg.com/express-jwt/-/express-jwt-6.1.2.tgz#4a6cc11d1dcff6f23126dd79ec5b2b441333e78b"
@@ -7441,6 +7431,25 @@ graphemer@^1.4.0:
74417431
resolved "https://registry.yarnpkg.com/graphemer/-/graphemer-1.4.0.tgz#fb2f1d55e0e3a1849aeffc90c4fa0dd53a0e66c6"
74427432
integrity sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==
74437433

7434+
graphql-http@^1.22.0:
7435+
version "1.22.0"
7436+
resolved "https://registry.yarnpkg.com/graphql-http/-/graphql-http-1.22.0.tgz#967bad279747ba5e1c9dd85b644c6b4f3dfa88f2"
7437+
integrity sha512-9RBUlGJWBFqz9LwfpmAbjJL/8j/HCNkZwPBU5+Bfmwez+1Ay43DocMNQYpIWsWqH0Ftv6PTNAh2aRnnMCBJgLw==
7438+
7439+
graphql-playground-html@^1.6.30:
7440+
version "1.6.30"
7441+
resolved "https://registry.yarnpkg.com/graphql-playground-html/-/graphql-playground-html-1.6.30.tgz#14c2a8eb7fc17bfeb1a746bbb28a11e34bf0b391"
7442+
integrity sha512-tpCujhsJMva4aqE8ULnF7/l3xw4sNRZcSHu+R00VV+W0mfp+Q20Plvcrp+5UXD+2yS6oyCXncA+zoQJQqhGCEw==
7443+
dependencies:
7444+
xss "^1.0.6"
7445+
7446+
graphql-playground-middleware-express@^1.7.23:
7447+
version "1.7.23"
7448+
resolved "https://registry.yarnpkg.com/graphql-playground-middleware-express/-/graphql-playground-middleware-express-1.7.23.tgz#95aba44d801ff3c08b2246917d2901d2e7c35d3d"
7449+
integrity sha512-M/zbTyC1rkgiQjFSgmzAv6umMHOphYLNWZp6Ye5QrD77WfGOOoSqDsVmGUczc2pDkEPEzzGB/bvBO5rdzaTRgw==
7450+
dependencies:
7451+
graphql-playground-html "^1.6.30"
7452+
74447453
graphql-tag@^2.12.3:
74457454
version "2.12.6"
74467455
resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.12.6.tgz#d441a569c1d2537ef10ca3d1633b48725329b5f1"
@@ -7611,17 +7620,6 @@ http-cache-semantics@^4.1.1:
76117620
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a"
76127621
integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==
76137622

7614-
7615-
version "1.8.0"
7616-
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.8.0.tgz#75d1bbe497e1044f51e4ee9e704a62f28d336507"
7617-
integrity sha512-4I8r0C5JDhT5VkvI47QktDW75rNlGVsUf/8hzjCC/wkWI/jdTRmBb9aI7erSG82r1bjKY3F6k28WnsVxB1C73A==
7618-
dependencies:
7619-
depd "~1.1.2"
7620-
inherits "2.0.4"
7621-
setprototypeof "1.2.0"
7622-
statuses ">= 1.5.0 < 2"
7623-
toidentifier "1.0.0"
7624-
76257623
76267624
version "2.0.0"
76277625
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-2.0.0.tgz#b7774a1486ef73cf7667ac9ae0858c012c57b9d3"
@@ -10524,7 +10522,7 @@ range-parser@~1.2.1:
1052410522
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
1052510523
integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==
1052610524

10527-
[email protected], raw-body@^2.4.1:
10525+
1052810526
version "2.5.2"
1052910527
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.5.2.tgz#99febd83b90e08975087e8f1f9419a149366b68a"
1053010528
integrity sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==
@@ -11433,11 +11431,6 @@ [email protected]:
1143311431
resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"
1143411432
integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==
1143511433

11436-
"statuses@>= 1.5.0 < 2":
11437-
version "1.5.0"
11438-
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
11439-
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==
11440-
1144111434
std-env@^3.3.3:
1144211435
version "3.3.3"
1144311436
resolved "https://registry.yarnpkg.com/std-env/-/std-env-3.3.3.tgz#a54f06eb245fdcfef53d56f3c0251f1d5c3d01fe"
@@ -11790,11 +11783,6 @@ to-regex@^3.0.1, to-regex@^3.0.2:
1179011783
regex-not "^1.0.2"
1179111784
safe-regex "^1.1.0"
1179211785

11793-
11794-
version "1.0.0"
11795-
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
11796-
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
11797-
1179811786
1179911787
version "1.0.1"
1180011788
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35"
@@ -12605,6 +12593,14 @@ xmlchars@^2.2.0:
1260512593
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"
1260612594
integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==
1260712595

12596+
xss@^1.0.6:
12597+
version "1.0.15"
12598+
resolved "https://registry.yarnpkg.com/xss/-/xss-1.0.15.tgz#96a0e13886f0661063028b410ed1b18670f4e59a"
12599+
integrity sha512-FVdlVVC67WOIPvfOwhoMETV72f6GbW7aOabBC3WxN/oUdoEMDyLz4OgRv5/gck2ZeNqEQu+Tb0kloovXOfpYVg==
12600+
dependencies:
12601+
commander "^2.20.3"
12602+
cssfilter "0.0.10"
12603+
1260812604
1260912605
version "4.38.3"
1261012606
resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.38.3.tgz#4e15e7ad3aa0ca1eea2010548a5379966d8f1075"

0 commit comments

Comments
 (0)