Skip to content

Commit

Permalink
fix(postgraphile): check pgConfig constructor's function in case of u…
Browse files Browse the repository at this point in the history
…glify (#992)
  • Loading branch information
Niicck authored and benjie committed Feb 9, 2019
1 parent e96c578 commit 419280d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/postgraphile/postgraphile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 419280d

Please sign in to comment.