Skip to content

Commit 5cfec34

Browse files
committed
use try-catch to simplify instanceOf check
1 parent d811c97 commit 5cfec34

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/jsutils/instanceOf.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import { inspect } from './inspect.js';
22

3+
function isProduction(): boolean {
4+
try {
5+
// TODO: add checks for other environments
6+
// eslint-disable-next-line no-undef
7+
return process.env.NODE_ENV === 'production';
8+
/* c8 ignore start */
9+
} catch {
10+
return true;
11+
}
12+
/* c8 ignore stop */
13+
}
14+
315
/**
416
* A replacement for instanceof which includes an error warning when multi-realm
517
* constructors are detected.
@@ -9,7 +21,7 @@ import { inspect } from './inspect.js';
921
export const instanceOf: (value: unknown, constructor: Constructor) => boolean =
1022
/* c8 ignore next 6 */
1123
// FIXME: https://github.com/graphql/graphql-js/issues/2317
12-
globalThis.process != null && globalThis.process.env.NODE_ENV === 'production'
24+
isProduction()
1325
? function instanceOf(value: unknown, constructor: Constructor): boolean {
1426
return value instanceof constructor;
1527
}

0 commit comments

Comments
 (0)