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