-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces new predicate and assertion functions for each kind of type mirroring the existing ones for the higher order types. It also includes predicates for directives and schema. This should remove the need to use `instanceof` in any usage of GraphQL.js This consolidates the checking of instances which generalizes the cross-realm/multiple-module check so that the clearer error message is provided in nearly all scenarios, reducing confusion. This also replaces nearly all `instanceof` with new predicate functions internally. Fixes #1134
- Loading branch information
Showing
31 changed files
with
652 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
/** | ||
* A replacement for instanceof which includes an error warning when multi-realm | ||
* constructors are detected. | ||
*/ | ||
declare function instanceOf( | ||
value: mixed, | ||
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. | ||
Ensure that there is only one instance of "graphql" in the node_modules | ||
directory. If different versions of "graphql" are the dependencies of other | ||
relied on modules, use "resolutions" to ensure only one version is installed. | ||
https://yarnpkg.com/en/docs/selective-version-resolutions | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.