Skip to content

Commit df19851

Browse files
authored
fix: upgrade Graphile Engine (#1702)
1 parent 4adbd42 commit df19851

File tree

10 files changed

+82
-181
lines changed

10 files changed

+82
-181
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@
5252
"dependencies": {
5353
"@graphile/lru": "4.11.0",
5454
"@types/json5": "^0.0.30",
55-
"@types/jsonwebtoken": "^8.3.2",
55+
"@types/jsonwebtoken": "^9.0.1",
5656
"@types/pg": ">=6 <9",
5757
"@types/ws": "^7.4.0",
5858
"body-parser": "^1.15.2",
5959
"chalk": "^2.4.2",
6060
"commander": "^2.19.0",
6161
"debug": "^4.1.1",
6262
"finalhandler": "^1.0.6",
63-
"graphile-build": "4.12.3",
64-
"graphile-build-pg": "4.12.3",
65-
"graphile-utils": "^4.12.3",
63+
"graphile-build": "4.13.0",
64+
"graphile-build-pg": "4.13.0",
65+
"graphile-utils": "^4.13.0",
6666
"graphql": "^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.2 || ^15.0.0",
6767
"graphql-ws": "^5.6.2",
6868
"http-errors": "^1.5.1",
@@ -72,8 +72,8 @@
7272
"parseurl": "^1.3.2",
7373
"pg": ">=6.1.0 <9",
7474
"pg-connection-string": "^2.0.0",
75-
"pg-sql2": "4.12.3",
76-
"postgraphile-core": "4.12.3",
75+
"pg-sql2": "4.13.0",
76+
"postgraphile-core": "4.13.0",
7777
"subscriptions-transport-ws": "^0.9.18",
7878
"tslib": "^2.1.0",
7979
"ws": "^7.4.2"
@@ -96,7 +96,7 @@
9696
"@types/koa-compress": "^4.0.1",
9797
"@types/lru-cache": "^5.1.0",
9898
"@types/morgan": "^1.9.2",
99-
"@types/node": "^10.9.4",
99+
"@types/node": "^12.0.0",
100100
"@types/parseurl": "^1.3.1",
101101
"@types/restify": "^8.4.2",
102102
"@typescript-eslint/eslint-plugin": "^4.14.0",

scripts/build

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
set -e
44
cd $(dirname $0)/..
55

6-
npm_bin=$(npm bin)
7-
86
echo "Cleaning build"
97
rm -rf build build-turbo
108
mkdir build build-turbo
@@ -13,9 +11,9 @@ echo "Preparing assets"
1311
scripts/make-assets
1412

1513
echo "Compiling with TypeScript"
16-
"$npm_bin"/tsc --target esnext --lib esnext --outDir build-turbo --declarationDir build-turbo
14+
npx --no-install tsc --target esnext --lib esnext --outDir build-turbo --declarationDir build-turbo
1715
echo "Compiling with TypeScript and backwards compatibility"
18-
"$npm_bin"/tsc
16+
npx --no-install tsc
1917

2018
echo "Removing tests/mocks"
2119
find build -wholename '*/__tests__/*' -delete

scripts/dev

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set -e
55
echo "Running dev (don't forget to 'yarn make-assets' if you've changed GraphiQL / favicon / etc)..."
66
cd $(dirname $0)/..
77

8-
npm_bin=$(npm bin)
98

109
export POSTGRAPHILE_ENV=development
1110
export BROWSER=none
@@ -18,10 +17,10 @@ if [ "$1" = "--" ]; then
1817
echo ' export DEBUG="postgraphile*,graphile-build:warn,-postgraphile:graphql,-postgraphile:postgres:explain"'
1918
fi
2019
shift
21-
$npm_bin/ts-node --transpile-only src/postgraphile/cli.ts "$@" &
20+
npx --no-install ts-node --transpile-only src/postgraphile/cli.ts "$@" &
2221
else
2322
export DEBUG=${DEBUG-postgraphile*,graphile-build:warn,-postgraphile:graphql,-postgraphile:postgres:explain}
24-
$npm_bin/nodemon \
23+
npx --no-install nodemon \
2524
--watch ../packages/postgraphile-core/node8plus \
2625
--watch ../packages/graphile-build-pg/node8plus \
2726
--watch ../packages/graphile-build/node8plus \
@@ -31,7 +30,7 @@ else
3130
--ignore __mocks__ \
3231
--ignore src/postgraphile/graphiql \
3332
--ext js,ts \
34-
--exec "$npm_bin/ts-node --transpile-only src/postgraphile/cli.ts $* --show-error-stack json --extended-errors hint,detail,errcode" &
33+
--exec "npx --no-install ts-node --transpile-only src/postgraphile/cli.ts $* --show-error-stack json --extended-errors hint,detail,errcode" &
3534
fi;
3635

3736
# Ensure forked process is killed even if we die unexpectedly

scripts/test

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#!/usr/bin/env bash
22

3-
npm_bin=$(npm bin)
4-
5-
$npm_bin/jest --maxWorkers 3 $@
3+
npx --no-install jest --maxWorkers 3 $@

scripts/typecheck

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
$(npm bin)/tsc --noEmit
3+
npx --no-install tsc --noEmit

src/interfaces.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import jwt = require('jsonwebtoken');
88
import { EventEmitter } from 'events';
99
import { PostGraphileResponse } from './postgraphile/http/frameworks';
1010
import { ShutdownActions } from './postgraphile/shutdownActions';
11+
import { KeyObject } from 'crypto';
1112

1213
type PromiseOrDirect<T> = T | Promise<T>;
1314
type DirectOrCallback<Request, T> = T | ((req: Request) => PromiseOrDirect<T>);
@@ -238,7 +239,7 @@ export interface PostGraphileOptions<
238239
// The secret for your JSON web tokens. This will be used to verify tokens in
239240
// the `Authorization` header, and signing JWT tokens you return in
240241
// procedures.
241-
jwtSecret?: jwt.Secret;
242+
jwtSecret?: Exclude<jwt.Secret, KeyObject>;
242243
// The public key to verify the JWT when signed with RS265 or ES256 algorithms.
243244
jwtPublicKey?: jwt.Secret | jwt.GetPublicKeyOrSecret;
244245
// Options with which to perform JWT verification - see
@@ -389,7 +390,7 @@ export interface HttpRequestHandler<
389390
export interface WithPostGraphileContextOptions {
390391
pgPool: Pool;
391392
jwtToken?: string;
392-
jwtSecret?: jwt.Secret;
393+
jwtSecret?: Exclude<jwt.Secret, KeyObject>;
393394
jwtPublicKey?: jwt.Secret | jwt.GetPublicKeyOrSecret;
394395
jwtAudiences?: Array<string>;
395396
jwtRole?: Array<string>;

src/postgraphile/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ if (noServer) {
862862
// some instructions and other interesting information.
863863
server.listen(port, hostname, () => {
864864
const address = server.address();
865-
const actualPort = typeof address === 'string' ? port : address.port;
865+
const actualPort = typeof address === 'string' || address == null ? port : address.port;
866866
const self = cluster.isMaster
867867
? isDev
868868
? `server (pid=${process.pid})`

src/postgraphile/http/createPostGraphileHttpRequestHandler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,11 @@ export default function createPostGraphileHttpRequestHandler(
415415
firstRequestHandler = null;
416416
let graphqlRouteForWs = graphqlRoute;
417417

418-
const { pathname = '' } = parseUrl(req) || {};
419-
const { pathname: originalPathname = '' } = parseUrl.original(req) || {};
418+
const parsed = parseUrl(req) || { pathname: '' };
419+
const pathname = parsed && typeof parsed.pathname === 'string' ? parsed.pathname : '';
420+
const parsed2 = parseUrl.original(req) || { pathname: '' };
421+
const originalPathname =
422+
parsed2 && typeof parsed2.pathname === 'string' ? parsed2.pathname : '';
420423
if (originalPathname !== pathname && originalPathname.endsWith(pathname)) {
421424
const base = originalPathname.slice(0, originalPathname.length - pathname.length);
422425
// Our websocket GraphQL route must be at a different place

src/postgraphile/http/subscriptions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export async function enhanceHttpServerWithWebSockets<
154154
statusCode: number,
155155
_statusMessage?: OutgoingHttpHeaders | string | undefined,
156156
headers?: OutgoingHttpHeaders | undefined,
157-
): void => {
157+
): Response => {
158158
if (statusCode && statusCode > 200) {
159159
// tslint:disable-next-line no-console
160160
console.error(
@@ -168,6 +168,7 @@ export async function enhanceHttpServerWithWebSockets<
168168
);
169169
socket.close();
170170
}
171+
return dummyRes!;
171172
};
172173
await applyMiddleware(options.websocketMiddlewares, req, dummyRes);
173174

@@ -526,7 +527,7 @@ export async function enhanceHttpServerWithWebSockets<
526527
// both v0 and v1, v1 will prevail
527528
v1Wss;
528529
if (wss) {
529-
wss.handleUpgrade(req, socket, head, ws => {
530+
wss.handleUpgrade(req, socket as any, head, ws => {
530531
wss.emit('connection', ws, req);
531532
});
532533
}

0 commit comments

Comments
 (0)