@@ -2,7 +2,6 @@ import { devAssert } from '../jsutils/devAssert';
2
2
import { didYouMean } from '../jsutils/didYouMean' ;
3
3
import { identityFunc } from '../jsutils/identityFunc' ;
4
4
import { inspect } from '../jsutils/inspect' ;
5
- import { instanceOf } from '../jsutils/instanceOf' ;
6
5
import { isObjectLike } from '../jsutils/isObjectLike' ;
7
6
import { keyMap } from '../jsutils/keyMap' ;
8
7
import { keyValMap } from '../jsutils/keyValMap' ;
@@ -75,11 +74,17 @@ export function assertType(type: unknown): GraphQLType {
75
74
return type ;
76
75
}
77
76
77
+ const isGraphQLScalarTypeSymbol = Symbol . for ( 'GraphQLScalarType' ) ;
78
+
78
79
/**
79
80
* There are predicates for each kind of GraphQL type.
80
81
*/
81
82
export function isScalarType ( type : unknown ) : type is GraphQLScalarType {
82
- return instanceOf ( type , GraphQLScalarType ) ;
83
+ return (
84
+ typeof type === 'object' &&
85
+ type != null &&
86
+ isGraphQLScalarTypeSymbol in type
87
+ ) ;
83
88
}
84
89
85
90
export function assertScalarType ( type : unknown ) : GraphQLScalarType {
@@ -89,8 +94,14 @@ export function assertScalarType(type: unknown): GraphQLScalarType {
89
94
return type ;
90
95
}
91
96
97
+ const isGraphQLObjectTypeSymbol = Symbol . for ( 'GraphQLObjectType' ) ;
98
+
92
99
export function isObjectType ( type : unknown ) : type is GraphQLObjectType {
93
- return instanceOf ( type , GraphQLObjectType ) ;
100
+ return (
101
+ typeof type === 'object' &&
102
+ type != null &&
103
+ isGraphQLObjectTypeSymbol in type
104
+ ) ;
94
105
}
95
106
96
107
export function assertObjectType ( type : unknown ) : GraphQLObjectType {
@@ -100,8 +111,14 @@ export function assertObjectType(type: unknown): GraphQLObjectType {
100
111
return type ;
101
112
}
102
113
114
+ const isGraphQLInterfaceTypeSymbol = Symbol . for ( 'GraphQLInterfaceType' ) ;
115
+
103
116
export function isInterfaceType ( type : unknown ) : type is GraphQLInterfaceType {
104
- return instanceOf ( type , GraphQLInterfaceType ) ;
117
+ return (
118
+ typeof type === 'object' &&
119
+ type != null &&
120
+ isGraphQLInterfaceTypeSymbol in type
121
+ ) ;
105
122
}
106
123
107
124
export function assertInterfaceType ( type : unknown ) : GraphQLInterfaceType {
@@ -113,8 +130,12 @@ export function assertInterfaceType(type: unknown): GraphQLInterfaceType {
113
130
return type ;
114
131
}
115
132
133
+ const isGraphQLUnionTypeSymbol = Symbol . for ( 'GraphQLUnionType' ) ;
134
+
116
135
export function isUnionType ( type : unknown ) : type is GraphQLUnionType {
117
- return instanceOf ( type , GraphQLUnionType ) ;
136
+ return (
137
+ typeof type === 'object' && type != null && isGraphQLUnionTypeSymbol in type
138
+ ) ;
118
139
}
119
140
120
141
export function assertUnionType ( type : unknown ) : GraphQLUnionType {
@@ -124,8 +145,12 @@ export function assertUnionType(type: unknown): GraphQLUnionType {
124
145
return type ;
125
146
}
126
147
148
+ const isGraphQLEnumTypeSymbol = Symbol . for ( 'GraphQLEnumType' ) ;
149
+
127
150
export function isEnumType ( type : unknown ) : type is GraphQLEnumType {
128
- return instanceOf ( type , GraphQLEnumType ) ;
151
+ return (
152
+ typeof type === 'object' && type != null && isGraphQLEnumTypeSymbol in type
153
+ ) ;
129
154
}
130
155
131
156
export function assertEnumType ( type : unknown ) : GraphQLEnumType {
@@ -135,10 +160,16 @@ export function assertEnumType(type: unknown): GraphQLEnumType {
135
160
return type ;
136
161
}
137
162
163
+ const isGraphQLInputObjectTypeSymbol = Symbol . for ( 'GraphQLInputObjectType' ) ;
164
+
138
165
export function isInputObjectType (
139
166
type : unknown ,
140
167
) : type is GraphQLInputObjectType {
141
- return instanceOf ( type , GraphQLInputObjectType ) ;
168
+ return (
169
+ typeof type === 'object' &&
170
+ type != null &&
171
+ isGraphQLInputObjectTypeSymbol in type
172
+ ) ;
142
173
}
143
174
144
175
export function assertInputObjectType ( type : unknown ) : GraphQLInputObjectType {
@@ -150,6 +181,8 @@ export function assertInputObjectType(type: unknown): GraphQLInputObjectType {
150
181
return type ;
151
182
}
152
183
184
+ const isGraphQLListTypeSymbol = Symbol . for ( 'GraphQLListType' ) ;
185
+
153
186
export function isListType (
154
187
type : GraphQLInputType ,
155
188
) : type is GraphQLList < GraphQLInputType > ;
@@ -158,7 +191,9 @@ export function isListType(
158
191
) : type is GraphQLList < GraphQLOutputType > ;
159
192
export function isListType ( type : unknown ) : type is GraphQLList < GraphQLType > ;
160
193
export function isListType ( type : unknown ) : type is GraphQLList < GraphQLType > {
161
- return instanceOf ( type , GraphQLList ) ;
194
+ return (
195
+ typeof type === 'object' && type != null && isGraphQLListTypeSymbol in type
196
+ ) ;
162
197
}
163
198
164
199
export function assertListType ( type : unknown ) : GraphQLList < GraphQLType > {
@@ -168,6 +203,8 @@ export function assertListType(type: unknown): GraphQLList<GraphQLType> {
168
203
return type ;
169
204
}
170
205
206
+ const isGraphQLNonNullTypeSymbol = Symbol . for ( 'GraphQLNonNullType' ) ;
207
+
171
208
export function isNonNullType (
172
209
type : GraphQLInputType ,
173
210
) : type is GraphQLNonNull < GraphQLNullableInputType > ;
@@ -180,7 +217,11 @@ export function isNonNullType(
180
217
export function isNonNullType (
181
218
type : unknown ,
182
219
) : type is GraphQLNonNull < GraphQLNullableType > {
183
- return instanceOf ( type , GraphQLNonNull ) ;
220
+ return (
221
+ typeof type === 'object' &&
222
+ type != null &&
223
+ isGraphQLNonNullTypeSymbol in type
224
+ ) ;
184
225
}
185
226
186
227
export function assertNonNullType ( type : unknown ) : GraphQLNonNull < GraphQLType > {
@@ -319,6 +360,7 @@ export function assertAbstractType(type: unknown): GraphQLAbstractType {
319
360
* ```
320
361
*/
321
362
export class GraphQLList < T extends GraphQLType > {
363
+ readonly [ isGraphQLListTypeSymbol ] : true = true ;
322
364
readonly ofType : T ;
323
365
324
366
constructor ( ofType : T ) {
@@ -365,6 +407,7 @@ export class GraphQLList<T extends GraphQLType> {
365
407
* Note: the enforcement of non-nullability occurs within the executor.
366
408
*/
367
409
export class GraphQLNonNull < T extends GraphQLNullableType > {
410
+ readonly [ isGraphQLNonNullTypeSymbol ] : true = true ;
368
411
readonly ofType : T ;
369
412
370
413
constructor ( ofType : T ) {
@@ -555,6 +598,7 @@ export interface GraphQLScalarTypeExtensions {
555
598
* ```
556
599
*/
557
600
export class GraphQLScalarType < TInternal = unknown , TExternal = TInternal > {
601
+ readonly [ isGraphQLScalarTypeSymbol ] : true = true ;
558
602
name : string ;
559
603
description : Maybe < string > ;
560
604
specifiedByURL : Maybe < string > ;
@@ -725,6 +769,7 @@ export interface GraphQLObjectTypeExtensions<_TSource = any, _TContext = any> {
725
769
* ```
726
770
*/
727
771
export class GraphQLObjectType < TSource = any , TContext = any > {
772
+ readonly [ isGraphQLObjectTypeSymbol ] : true = true ;
728
773
name : string ;
729
774
description : Maybe < string > ;
730
775
isTypeOf : Maybe < GraphQLIsTypeOfFn < TSource , TContext > > ;
@@ -1078,6 +1123,7 @@ export interface GraphQLInterfaceTypeExtensions {
1078
1123
* ```
1079
1124
*/
1080
1125
export class GraphQLInterfaceType {
1126
+ readonly [ isGraphQLInterfaceTypeSymbol ] : true = true ;
1081
1127
name : string ;
1082
1128
description : Maybe < string > ;
1083
1129
resolveType : Maybe < GraphQLTypeResolver < any , any > > ;
@@ -1207,6 +1253,7 @@ export interface GraphQLUnionTypeExtensions {
1207
1253
* ```
1208
1254
*/
1209
1255
export class GraphQLUnionType {
1256
+ readonly [ isGraphQLUnionTypeSymbol ] : true = true ;
1210
1257
name : string ;
1211
1258
description : Maybe < string > ;
1212
1259
resolveType : Maybe < GraphQLTypeResolver < any , any > > ;
@@ -1334,6 +1381,7 @@ export interface GraphQLEnumTypeExtensions {
1334
1381
* will be used as its internal value.
1335
1382
*/
1336
1383
export class GraphQLEnumType /* <T> */ {
1384
+ readonly [ isGraphQLEnumTypeSymbol ] : true = true ;
1337
1385
name : string ;
1338
1386
description : Maybe < string > ;
1339
1387
extensions : Readonly < GraphQLEnumTypeExtensions > ;
@@ -1574,6 +1622,7 @@ export interface GraphQLInputObjectTypeExtensions {
1574
1622
* ```
1575
1623
*/
1576
1624
export class GraphQLInputObjectType {
1625
+ readonly [ isGraphQLInputObjectTypeSymbol ] : true = true ;
1577
1626
name : string ;
1578
1627
description : Maybe < string > ;
1579
1628
extensions : Readonly < GraphQLInputObjectTypeExtensions > ;
0 commit comments