Skip to content

Commit

Permalink
use try-catch to simplify checks
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed May 3, 2024
1 parent d811c97 commit 03b4505
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/jsutils/instanceOf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { inspect } from './inspect.js';

function isProduction(): boolean {
try {
// TODO: add checks for other environments
// eslint-disable-next-line no-undef
return process.env.NODE_ENV === 'production';
} catch {
return true;
}
}

/**
* A replacement for instanceof which includes an error warning when multi-realm
* constructors are detected.
Expand All @@ -9,7 +19,7 @@ import { inspect } from './inspect.js';
export const instanceOf: (value: unknown, constructor: Constructor) => boolean =
/* c8 ignore next 6 */
// FIXME: https://github.com/graphql/graphql-js/issues/2317
globalThis.process != null && globalThis.process.env.NODE_ENV === 'production'
isProduction()
? function instanceOf(value: unknown, constructor: Constructor): boolean {
return value instanceof constructor;
}
Expand Down

0 comments on commit 03b4505

Please sign in to comment.