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');
|
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 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | function isTypeSubTypeOf(schema, maybeSubType, superType) {
|
49 |
|
50 | if (maybeSubType === superType) {
|
51 | return true;
|
52 | }
|
53 |
|
54 |
|
55 | if ((0, _definition.isNonNullType)(superType)) {
|
56 | if ((0, _definition.isNonNullType)(maybeSubType)) {
|
57 | return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
58 | }
|
59 | return false;
|
60 | }
|
61 | if ((0, _definition.isNonNullType)(maybeSubType)) {
|
62 |
|
63 | return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);
|
64 | }
|
65 |
|
66 |
|
67 | if ((0, _definition.isListType)(superType)) {
|
68 | if ((0, _definition.isListType)(maybeSubType)) {
|
69 | return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
|
70 | }
|
71 | return false;
|
72 | }
|
73 | if ((0, _definition.isListType)(maybeSubType)) {
|
74 |
|
75 | return false;
|
76 | }
|
77 |
|
78 |
|
79 |
|
80 | if ((0, _definition.isAbstractType)(superType) && (0, _definition.isObjectType)(maybeSubType) && schema.isPossibleType(superType, maybeSubType)) {
|
81 | return true;
|
82 | }
|
83 |
|
84 |
|
85 | return false;
|
86 | }
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | function doTypesOverlap(schema, typeA, typeB) {
|
98 |
|
99 | var _typeB = typeB;
|
100 |
|
101 |
|
102 | if (typeA === _typeB) {
|
103 | return true;
|
104 | }
|
105 |
|
106 | if ((0, _definition.isAbstractType)(typeA)) {
|
107 | if ((0, _definition.isAbstractType)(_typeB)) {
|
108 |
|
109 |
|
110 | return schema.getPossibleTypes(typeA).some(function (type) {
|
111 | return schema.isPossibleType(_typeB, type);
|
112 | });
|
113 | }
|
114 |
|
115 | return schema.isPossibleType(typeA, _typeB);
|
116 | }
|
117 |
|
118 | if ((0, _definition.isAbstractType)(_typeB)) {
|
119 |
|
120 | return schema.isPossibleType(_typeB, typeA);
|
121 | }
|
122 |
|
123 |
|
124 | return false;
|
125 | } |
\ | No newline at end of file |