Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only trigger "one instance of graphql" error in DEV environments. #1174

Merged
merged 1 commit into from Dec 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/jsutils/instanceOf.js
Expand Up @@ -16,16 +16,18 @@ declare function instanceOf(
constructor: mixed,
): boolean %checks(value instanceof constructor);

// eslint-disable-next-line no-redeclare
export default function instanceOf(value, constructor) {
if (value instanceof constructor) {
return true;
}
if (value) {
const valueConstructor = value.constructor;
if (valueConstructor && valueConstructor.name === constructor.name) {
throw new Error(
`Cannot use ${constructor.name} "${value}" from another module or realm.
export default (process && process.env.NODE_ENV !== 'production'
? // eslint-disable-next-line no-shadow
function instanceOf(value: any, constructor: any) {
if (value instanceof constructor) {
return true;
}
if (value) {
const valueClass = value.constructor;
const className = constructor.name;
if (valueClass && valueClass.name === className) {
throw new Error(
`Cannot use ${className} "${value}" from another module or realm.

Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
Expand All @@ -37,8 +39,12 @@ Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.`,
);
);
}
}
return false;
}
}
return false;
}
: // eslint-disable-next-line no-shadow
function instanceOf(value: any, constructor: any) {
return value instanceof constructor;
});