1 | /**
|
2 | * Copyright (c) Facebook, Inc. and its affiliates.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | * strict-local
|
8 | * @format
|
9 | */
|
10 | ;
|
11 |
|
12 | /**
|
13 | * Determine if a type is the same type (same name and class) as another type.
|
14 | * Needed if we're comparing IRs created at different times: we don't yet have
|
15 | * an IR schema, so the type we assign to an IR field could be !== than
|
16 | * what we assign to it after adding some schema definitions or extensions.
|
17 | */
|
18 | function isEquivalentType(typeA, typeB) {
|
19 | // Easy short-circuit: equal types are equal.
|
20 | if (typeA === typeB) {
|
21 | return true;
|
22 | } // If either type is non-null, the other must also be non-null.
|
23 |
|
24 |
|
25 | if (typeA instanceof require("graphql").GraphQLNonNull && typeB instanceof require("graphql").GraphQLNonNull) {
|
26 | return isEquivalentType(typeA.ofType, typeB.ofType);
|
27 | } // If either type is a list, the other must also be a list.
|
28 |
|
29 |
|
30 | if (typeA instanceof require("graphql").GraphQLList && typeB instanceof require("graphql").GraphQLList) {
|
31 | return isEquivalentType(typeA.ofType, typeB.ofType);
|
32 | } // Make sure the two types are of the same class
|
33 |
|
34 |
|
35 | if (typeA.constructor.name === typeB.constructor.name) {
|
36 | var rawA = require("./GraphQLSchemaUtils").getRawType(typeA);
|
37 |
|
38 | var rawB = require("./GraphQLSchemaUtils").getRawType(typeB); // And they must have the exact same name
|
39 |
|
40 |
|
41 | return rawA.name === rawB.name;
|
42 | } // Otherwise the types are not equal.
|
43 |
|
44 |
|
45 | return false;
|
46 | }
|
47 |
|
48 | module.exports = isEquivalentType; |
\ | No newline at end of file |