From 419280d6afc7d12813a461350aaf11561b273eb3 Mon Sep 17 00:00:00 2001 From: Nick Ivons <14187277+Niicck@users.noreply.github.com> Date: Sat, 9 Feb 2019 10:25:11 -0600 Subject: [PATCH] fix(postgraphile): check pgConfig constructor's function in case of uglify (#992) --- src/postgraphile/postgraphile.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/postgraphile/postgraphile.ts b/src/postgraphile/postgraphile.ts index e2b1ab9df9..3564a1244b 100644 --- a/src/postgraphile/postgraphile.ts +++ b/src/postgraphile/postgraphile.ts @@ -190,6 +190,14 @@ function handleFatalError(error: Error, when: string): never { return null as never; } +function hasPoolConstructor(obj: mixed): boolean { + return ( + // tslint:disable-next-line no-any + (obj && typeof obj.constructor === 'function' && obj.constructor === (Pool as any).super_) || + false + ); +} + function constructorName(obj: mixed): string | null { return ( (obj && @@ -221,6 +229,7 @@ function toPgPool(poolOrConfig: any): Pool { // tslint:disable-next-line no-any function quacksLikePgPool(pgConfig: any): pgConfig is Pool { if (pgConfig instanceof Pool) return true; + if (hasPoolConstructor(pgConfig)) return true; // A diagnosis of exclusion if (!pgConfig || typeof pgConfig !== 'object') return false;