Skip to content

Commit

Permalink
fix: upgrade Graphile Engine (#1702)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Jan 12, 2023
1 parent 4adbd42 commit df19851
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 181 deletions.
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -52,17 +52,17 @@
"dependencies": {
"@graphile/lru": "4.11.0",
"@types/json5": "^0.0.30",
"@types/jsonwebtoken": "^8.3.2",
"@types/jsonwebtoken": "^9.0.1",
"@types/pg": ">=6 <9",
"@types/ws": "^7.4.0",
"body-parser": "^1.15.2",
"chalk": "^2.4.2",
"commander": "^2.19.0",
"debug": "^4.1.1",
"finalhandler": "^1.0.6",
"graphile-build": "4.12.3",
"graphile-build-pg": "4.12.3",
"graphile-utils": "^4.12.3",
"graphile-build": "4.13.0",
"graphile-build-pg": "4.13.0",
"graphile-utils": "^4.13.0",
"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",
"graphql-ws": "^5.6.2",
"http-errors": "^1.5.1",
Expand All @@ -72,8 +72,8 @@
"parseurl": "^1.3.2",
"pg": ">=6.1.0 <9",
"pg-connection-string": "^2.0.0",
"pg-sql2": "4.12.3",
"postgraphile-core": "4.12.3",
"pg-sql2": "4.13.0",
"postgraphile-core": "4.13.0",
"subscriptions-transport-ws": "^0.9.18",
"tslib": "^2.1.0",
"ws": "^7.4.2"
Expand All @@ -96,7 +96,7 @@
"@types/koa-compress": "^4.0.1",
"@types/lru-cache": "^5.1.0",
"@types/morgan": "^1.9.2",
"@types/node": "^10.9.4",
"@types/node": "^12.0.0",
"@types/parseurl": "^1.3.1",
"@types/restify": "^8.4.2",
"@typescript-eslint/eslint-plugin": "^4.14.0",
Expand Down
6 changes: 2 additions & 4 deletions scripts/build
Expand Up @@ -3,8 +3,6 @@
set -e
cd $(dirname $0)/..

npm_bin=$(npm bin)

echo "Cleaning build"
rm -rf build build-turbo
mkdir build build-turbo
Expand All @@ -13,9 +11,9 @@ echo "Preparing assets"
scripts/make-assets

echo "Compiling with TypeScript"
"$npm_bin"/tsc --target esnext --lib esnext --outDir build-turbo --declarationDir build-turbo
npx --no-install tsc --target esnext --lib esnext --outDir build-turbo --declarationDir build-turbo
echo "Compiling with TypeScript and backwards compatibility"
"$npm_bin"/tsc
npx --no-install tsc

echo "Removing tests/mocks"
find build -wholename '*/__tests__/*' -delete
Expand Down
7 changes: 3 additions & 4 deletions scripts/dev
Expand Up @@ -5,7 +5,6 @@ set -e
echo "Running dev (don't forget to 'yarn make-assets' if you've changed GraphiQL / favicon / etc)..."
cd $(dirname $0)/..

npm_bin=$(npm bin)

export POSTGRAPHILE_ENV=development
export BROWSER=none
Expand All @@ -18,10 +17,10 @@ if [ "$1" = "--" ]; then
echo ' export DEBUG="postgraphile*,graphile-build:warn,-postgraphile:graphql,-postgraphile:postgres:explain"'
fi
shift
$npm_bin/ts-node --transpile-only src/postgraphile/cli.ts "$@" &
npx --no-install ts-node --transpile-only src/postgraphile/cli.ts "$@" &
else
export DEBUG=${DEBUG-postgraphile*,graphile-build:warn,-postgraphile:graphql,-postgraphile:postgres:explain}
$npm_bin/nodemon \
npx --no-install nodemon \
--watch ../packages/postgraphile-core/node8plus \
--watch ../packages/graphile-build-pg/node8plus \
--watch ../packages/graphile-build/node8plus \
Expand All @@ -31,7 +30,7 @@ else
--ignore __mocks__ \
--ignore src/postgraphile/graphiql \
--ext js,ts \
--exec "$npm_bin/ts-node --transpile-only src/postgraphile/cli.ts $* --show-error-stack json --extended-errors hint,detail,errcode" &
--exec "npx --no-install ts-node --transpile-only src/postgraphile/cli.ts $* --show-error-stack json --extended-errors hint,detail,errcode" &
fi;

# Ensure forked process is killed even if we die unexpectedly
Expand Down
4 changes: 1 addition & 3 deletions scripts/test
@@ -1,5 +1,3 @@
#!/usr/bin/env bash

npm_bin=$(npm bin)

$npm_bin/jest --maxWorkers 3 $@
npx --no-install jest --maxWorkers 3 $@
2 changes: 1 addition & 1 deletion scripts/typecheck
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

$(npm bin)/tsc --noEmit
npx --no-install tsc --noEmit
5 changes: 3 additions & 2 deletions src/interfaces.ts
Expand Up @@ -8,6 +8,7 @@ import jwt = require('jsonwebtoken');
import { EventEmitter } from 'events';
import { PostGraphileResponse } from './postgraphile/http/frameworks';
import { ShutdownActions } from './postgraphile/shutdownActions';
import { KeyObject } from 'crypto';

type PromiseOrDirect<T> = T | Promise<T>;
type DirectOrCallback<Request, T> = T | ((req: Request) => PromiseOrDirect<T>);
Expand Down Expand Up @@ -238,7 +239,7 @@ export interface PostGraphileOptions<
// The secret for your JSON web tokens. This will be used to verify tokens in
// the `Authorization` header, and signing JWT tokens you return in
// procedures.
jwtSecret?: jwt.Secret;
jwtSecret?: Exclude<jwt.Secret, KeyObject>;
// The public key to verify the JWT when signed with RS265 or ES256 algorithms.
jwtPublicKey?: jwt.Secret | jwt.GetPublicKeyOrSecret;
// Options with which to perform JWT verification - see
Expand Down Expand Up @@ -389,7 +390,7 @@ export interface HttpRequestHandler<
export interface WithPostGraphileContextOptions {
pgPool: Pool;
jwtToken?: string;
jwtSecret?: jwt.Secret;
jwtSecret?: Exclude<jwt.Secret, KeyObject>;
jwtPublicKey?: jwt.Secret | jwt.GetPublicKeyOrSecret;
jwtAudiences?: Array<string>;
jwtRole?: Array<string>;
Expand Down
2 changes: 1 addition & 1 deletion src/postgraphile/cli.ts
Expand Up @@ -862,7 +862,7 @@ if (noServer) {
// some instructions and other interesting information.
server.listen(port, hostname, () => {
const address = server.address();
const actualPort = typeof address === 'string' ? port : address.port;
const actualPort = typeof address === 'string' || address == null ? port : address.port;
const self = cluster.isMaster
? isDev
? `server (pid=${process.pid})`
Expand Down
7 changes: 5 additions & 2 deletions src/postgraphile/http/createPostGraphileHttpRequestHandler.ts
Expand Up @@ -415,8 +415,11 @@ export default function createPostGraphileHttpRequestHandler(
firstRequestHandler = null;
let graphqlRouteForWs = graphqlRoute;

const { pathname = '' } = parseUrl(req) || {};
const { pathname: originalPathname = '' } = parseUrl.original(req) || {};
const parsed = parseUrl(req) || { pathname: '' };
const pathname = parsed && typeof parsed.pathname === 'string' ? parsed.pathname : '';
const parsed2 = parseUrl.original(req) || { pathname: '' };
const originalPathname =
parsed2 && typeof parsed2.pathname === 'string' ? parsed2.pathname : '';
if (originalPathname !== pathname && originalPathname.endsWith(pathname)) {
const base = originalPathname.slice(0, originalPathname.length - pathname.length);
// Our websocket GraphQL route must be at a different place
Expand Down
5 changes: 3 additions & 2 deletions src/postgraphile/http/subscriptions.ts
Expand Up @@ -154,7 +154,7 @@ export async function enhanceHttpServerWithWebSockets<
statusCode: number,
_statusMessage?: OutgoingHttpHeaders | string | undefined,
headers?: OutgoingHttpHeaders | undefined,
): void => {
): Response => {
if (statusCode && statusCode > 200) {
// tslint:disable-next-line no-console
console.error(
Expand All @@ -168,6 +168,7 @@ export async function enhanceHttpServerWithWebSockets<
);
socket.close();
}
return dummyRes!;
};
await applyMiddleware(options.websocketMiddlewares, req, dummyRes);

Expand Down Expand Up @@ -526,7 +527,7 @@ export async function enhanceHttpServerWithWebSockets<
// both v0 and v1, v1 will prevail
v1Wss;
if (wss) {
wss.handleUpgrade(req, socket, head, ws => {
wss.handleUpgrade(req, socket as any, head, ws => {
wss.emit('connection', ws, req);
});
}
Expand Down

0 comments on commit df19851

Please sign in to comment.