Skip to content

Commit

Permalink
instanceOf: disable dev instanceOf checks if NODE_ENV not set
Browse files Browse the repository at this point in the history
development behavior should be opt in, not opt out

graphql#4075 (comment)
  • Loading branch information
yaacovCR committed Sep 9, 2024
1 parent 6c56e05 commit 6c6f846
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ extension:
- ts
node-option:
- 'loader=ts-node/esm/transpile-only'
require:
- './resources/mochaFixture.ts'
3 changes: 3 additions & 0 deletions resources/mochaFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function mochaGlobalSetup() {
process.env.NODE_ENV = 'development';
}
12 changes: 6 additions & 6 deletions src/jsutils/instanceOf.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { inspect } from './inspect.js';

/* c8 ignore next 3 */
const isProduction =
const isDevelopment =
globalThis.process != null &&
// eslint-disable-next-line no-undef
process.env.NODE_ENV === 'production';
process.env.NODE_ENV === 'development';

/**
* A replacement for instanceof which includes an error warning when multi-realm
Expand All @@ -15,11 +15,8 @@ const isProduction =
export const instanceOf: (value: unknown, constructor: Constructor) => boolean =
/* c8 ignore next 6 */
// FIXME: https://github.com/graphql/graphql-js/issues/2317
isProduction
isDevelopment
? function instanceOf(value: unknown, constructor: Constructor): boolean {
return value instanceof constructor;
}
: function instanceOf(value: unknown, constructor: Constructor): boolean {
if (value instanceof constructor) {
return true;
}
Expand Down Expand Up @@ -50,6 +47,9 @@ spurious results.`,
}
}
return false;
}
: function instanceOf(value: unknown, constructor: Constructor): boolean {
return value instanceof constructor;
};

interface Constructor extends Function {
Expand Down

0 comments on commit 6c6f846

Please sign in to comment.