@@ -36,6 +36,14 @@ export type GraphQLType =
36
36
GraphQLList < any > |
37
37
GraphQLNonNull < any > ;
38
38
39
+ export function assertType ( type : mixed ) : GraphQLType {
40
+ invariant (
41
+ isType ( type ) ,
42
+ `GraphQL: Expected ${ String ( type ) } to be a GraphQLType.`
43
+ ) ;
44
+ return ( type : any ) ;
45
+ }
46
+
39
47
export function isType ( type : mixed ) : boolean {
40
48
return (
41
49
type instanceof GraphQLScalarType ||
@@ -64,6 +72,14 @@ export type GraphQLInputType =
64
72
GraphQLList < GraphQLInputType >
65
73
> ;
66
74
75
+ export function assertInputType ( type : ?GraphQLType ) : GraphQLInputType {
76
+ invariant (
77
+ isInputType ( type ) ,
78
+ `GraphQL: Expected type ${ String ( type ) } to be a GraphQLInputType.`
79
+ ) ;
80
+ return ( type : any ) ;
81
+ }
82
+
67
83
export function isInputType ( type : ?GraphQLType ) : boolean {
68
84
const namedType = getNamedType ( type ) ;
69
85
return (
@@ -92,6 +108,14 @@ export type GraphQLOutputType =
92
108
GraphQLList < GraphQLOutputType >
93
109
> ;
94
110
111
+ export function assertOutputType ( type : ?GraphQLType ) : GraphQLOutputType {
112
+ invariant (
113
+ isOutputType ( type ) ,
114
+ `GraphQL: Expected type ${ String ( type ) } to be a GraphQLOutputType.` ,
115
+ ) ;
116
+ return ( type : any ) ;
117
+ }
118
+
95
119
export function isOutputType ( type : ?GraphQLType ) : boolean {
96
120
const namedType = getNamedType ( type ) ;
97
121
return (
@@ -110,6 +134,14 @@ export type GraphQLLeafType =
110
134
GraphQLScalarType |
111
135
GraphQLEnumType ;
112
136
137
+ export function assertLeafType ( type : ?GraphQLType ) : GraphQLLeafType {
138
+ invariant (
139
+ isLeafType ( type ) ,
140
+ `GraphQL: Expected type ${ String ( type ) } to be a GraphQLLeafType.` ,
141
+ ) ;
142
+ return ( type : any ) ;
143
+ }
144
+
113
145
export function isLeafType ( type : ?GraphQLType ) : boolean {
114
146
const namedType = getNamedType ( type ) ;
115
147
return (
@@ -126,6 +158,14 @@ export type GraphQLCompositeType =
126
158
GraphQLInterfaceType |
127
159
GraphQLUnionType ;
128
160
161
+ export function assertCompositeType ( type : ?GraphQLType ) : GraphQLCompositeType {
162
+ invariant (
163
+ isCompositeType ( type ) ,
164
+ `GraphQL: Expected type ${ String ( type ) } to be a GraphQLCompositeType.` ,
165
+ ) ;
166
+ return ( type : any ) ;
167
+ }
168
+
129
169
export function isCompositeType ( type : ?GraphQLType ) : boolean {
130
170
return (
131
171
type instanceof GraphQLObjectType ||
@@ -141,6 +181,14 @@ export type GraphQLAbstractType =
141
181
GraphQLInterfaceType |
142
182
GraphQLUnionType ;
143
183
184
+ export function assertAbstractType ( type : ?GraphQLType ) : GraphQLAbstractType {
185
+ invariant (
186
+ isAbstractType ( type ) ,
187
+ `GraphQL: Expected type ${ String ( type ) } to be a GraphQLAbstractType.` ,
188
+ ) ;
189
+ return ( type : any ) ;
190
+ }
191
+
144
192
export function isAbstractType ( type : ?GraphQLType ) : boolean {
145
193
return (
146
194
type instanceof GraphQLInterfaceType ||
0 commit comments