@@ -21,7 +21,7 @@ import type {
21
21
import type { GraphQLSchema } from './schema' ;
22
22
23
23
24
- // Predicates
24
+ // Predicates & Assertions
25
25
26
26
/**
27
27
* These are all of the possible kinds of types.
@@ -36,14 +36,6 @@ 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
-
47
39
export function isType ( type : mixed ) : boolean {
48
40
return (
49
41
type instanceof GraphQLScalarType ||
@@ -57,6 +49,14 @@ export function isType(type: mixed): boolean {
57
49
) ;
58
50
}
59
51
52
+ export function assertType ( type : mixed ) : GraphQLType {
53
+ invariant (
54
+ isType ( type ) ,
55
+ `Expected ${ String ( type ) } to be a GraphQL type.`
56
+ ) ;
57
+ return ( type : any ) ;
58
+ }
59
+
60
60
/**
61
61
* These types may be used as input types for arguments and directives.
62
62
*/
@@ -72,14 +72,6 @@ export type GraphQLInputType =
72
72
GraphQLList < GraphQLInputType >
73
73
> ;
74
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
-
83
75
export function isInputType ( type : ?GraphQLType ) : boolean {
84
76
const namedType = getNamedType ( type ) ;
85
77
return (
@@ -89,6 +81,14 @@ export function isInputType(type: ?GraphQLType): boolean {
89
81
) ;
90
82
}
91
83
84
+ export function assertInputType ( type : ?GraphQLType ) : GraphQLInputType {
85
+ invariant (
86
+ isInputType ( type ) ,
87
+ `Expected ${ String ( type ) } to be a GraphQL input type.`
88
+ ) ;
89
+ return ( type : any ) ;
90
+ }
91
+
92
92
/**
93
93
* These types may be used as output types as the result of fields.
94
94
*/
@@ -108,14 +108,6 @@ export type GraphQLOutputType =
108
108
GraphQLList < GraphQLOutputType >
109
109
> ;
110
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
-
119
111
export function isOutputType ( type : ?GraphQLType ) : boolean {
120
112
const namedType = getNamedType ( type ) ;
121
113
return (
@@ -127,21 +119,21 @@ export function isOutputType(type: ?GraphQLType): boolean {
127
119
) ;
128
120
}
129
121
122
+ export function assertOutputType ( type : ?GraphQLType ) : GraphQLOutputType {
123
+ invariant (
124
+ isOutputType ( type ) ,
125
+ `Expected ${ String ( type ) } to be a GraphQL output type.` ,
126
+ ) ;
127
+ return ( type : any ) ;
128
+ }
129
+
130
130
/**
131
131
* These types may describe types which may be leaf values.
132
132
*/
133
133
export type GraphQLLeafType =
134
134
GraphQLScalarType |
135
135
GraphQLEnumType ;
136
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
-
145
137
export function isLeafType ( type : ?GraphQLType ) : boolean {
146
138
const namedType = getNamedType ( type ) ;
147
139
return (
@@ -150,6 +142,14 @@ export function isLeafType(type: ?GraphQLType): boolean {
150
142
) ;
151
143
}
152
144
145
+ export function assertLeafType ( type : ?GraphQLType ) : GraphQLLeafType {
146
+ invariant (
147
+ isLeafType ( type ) ,
148
+ `Expected ${ String ( type ) } to be a GraphQL leaf type.` ,
149
+ ) ;
150
+ return ( type : any ) ;
151
+ }
152
+
153
153
/**
154
154
* These types may describe the parent context of a selection set.
155
155
*/
@@ -158,14 +158,6 @@ export type GraphQLCompositeType =
158
158
GraphQLInterfaceType |
159
159
GraphQLUnionType ;
160
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
-
169
161
export function isCompositeType ( type : ?GraphQLType ) : boolean {
170
162
return (
171
163
type instanceof GraphQLObjectType ||
@@ -174,28 +166,36 @@ export function isCompositeType(type: ?GraphQLType): boolean {
174
166
) ;
175
167
}
176
168
169
+ export function assertCompositeType ( type : ?GraphQLType ) : GraphQLCompositeType {
170
+ invariant (
171
+ isCompositeType ( type ) ,
172
+ `Expected ${ String ( type ) } to be a GraphQL composite type.` ,
173
+ ) ;
174
+ return ( type : any ) ;
175
+ }
176
+
177
177
/**
178
178
* These types may describe the parent context of a selection set.
179
179
*/
180
180
export type GraphQLAbstractType =
181
181
GraphQLInterfaceType |
182
182
GraphQLUnionType ;
183
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
-
192
184
export function isAbstractType ( type : ?GraphQLType ) : boolean {
193
185
return (
194
186
type instanceof GraphQLInterfaceType ||
195
187
type instanceof GraphQLUnionType
196
188
) ;
197
189
}
198
190
191
+ export function assertAbstractType ( type : ?GraphQLType ) : GraphQLAbstractType {
192
+ invariant (
193
+ isAbstractType ( type ) ,
194
+ `Expected ${ String ( type ) } to be a GraphQL abstract type.` ,
195
+ ) ;
196
+ return ( type : any ) ;
197
+ }
198
+
199
199
/**
200
200
* These types can all accept null as a value.
201
201
*/
0 commit comments