1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.isEqualType = isEqualType;
|
7 | exports.isTypeSubTypeOf = isTypeSubTypeOf;
|
8 | exports.doTypesOverlap = doTypesOverlap;
|
9 |
|
10 | var _definition = require("../type/definition.js");
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function isEqualType(typeA, typeB) {
|
16 |
|
17 | if (typeA === typeB) {
|
18 | return true;
|
19 | }
|
20 |
|
21 |
|
22 | if ((0, _definition.isNonNullType)(typeA) && (0, _definition.isNonNullType)(typeB)) {
|
23 | return isEqualType(typeA.ofType, typeB.ofType);
|
24 | }
|
25 |
|
26 |
|
27 | if ((0, _definition.isListType)(typeA) && (0, _definition.isListType)(typeB)) {
|
28 | return isEqualType(typeA.ofType, typeB.ofType);
|
29 | }
|
30 |
|
31 |
|
32 | return false;
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function isTypeSubTypeOf(schema, maybeSubType, superType) {
|
41 |
|
42 | if (maybeSubType === superType) {
|
43 | return true;
|
44 | }
|
45 |
|
46 |
|
47 | if ((0, _definition.isNonNullType)(superType)) {
|
48 | if ((0, _definition.isNonNullType)(maybeSubType)) {
|
49 | return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
50 | }
|
51 |
|
52 | return false;
|
53 | }
|
54 |
|
55 | if ((0, _definition.isNonNullType)(maybeSubType)) {
|
56 |
|
57 | return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);
|
58 | }
|
59 |
|
60 |
|
61 | if ((0, _definition.isListType)(superType)) {
|
62 | if ((0, _definition.isListType)(maybeSubType)) {
|
63 | return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
64 | }
|
65 |
|
66 | return false;
|
67 | }
|
68 |
|
69 | if ((0, _definition.isListType)(maybeSubType)) {
|
70 |
|
71 | return false;
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 | return (0, _definition.isAbstractType)(superType) && ((0, _definition.isInterfaceType)(maybeSubType) || (0, _definition.isObjectType)(maybeSubType)) && schema.isSubType(superType, maybeSubType);
|
77 | }
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | function doTypesOverlap(schema, typeA, typeB) {
|
90 |
|
91 | if (typeA === typeB) {
|
92 | return true;
|
93 | }
|
94 |
|
95 | if ((0, _definition.isAbstractType)(typeA)) {
|
96 | if ((0, _definition.isAbstractType)(typeB)) {
|
97 |
|
98 |
|
99 | return schema.getPossibleTypes(typeA).some(function (type) {
|
100 | return schema.isSubType(typeB, type);
|
101 | });
|
102 | }
|
103 |
|
104 |
|
105 | return schema.isSubType(typeA, typeB);
|
106 | }
|
107 |
|
108 | if ((0, _definition.isAbstractType)(typeB)) {
|
109 |
|
110 | return schema.isSubType(typeB, typeA);
|
111 | }
|
112 |
|
113 |
|
114 | return false;
|
115 | }
|