UNPKG

2.33 kBJavaScriptView Raw
1function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
3import inspect from "./inspect.mjs";
4/**
5 * A replacement for instanceof which includes an error warning when multi-realm
6 * constructors are detected.
7 */
8
9// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
10// See: https://webpack.js.org/guides/production/
11export default process.env.NODE_ENV === 'production' ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
12// eslint-disable-next-line no-shadow
13function instanceOf(value, constructor) {
14 return value instanceof constructor;
15} : // eslint-disable-next-line no-shadow
16function instanceOf(value, constructor) {
17 if (value instanceof constructor) {
18 return true;
19 }
20
21 if (_typeof(value) === 'object' && value !== null) {
22 var _value$constructor;
23
24 var className = constructor.prototype[Symbol.toStringTag];
25 var valueClassName = // We still need to support constructor's name to detect conflicts with older versions of this library.
26 Symbol.toStringTag in value ? value[Symbol.toStringTag] : (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name;
27
28 if (className === valueClassName) {
29 var stringifiedValue = inspect(value);
30 throw new Error("Cannot use ".concat(className, " \"").concat(stringifiedValue, "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));
31 }
32 }
33
34 return false;
35};