@@ -50,7 +50,6 @@ import type {
50
50
} from '../type/definition' ;
51
51
52
52
import {
53
- assertNullableType ,
54
53
GraphQLScalarType ,
55
54
GraphQLObjectType ,
56
55
GraphQLInterfaceType ,
@@ -89,31 +88,6 @@ export type BuildSchemaOptions = {
89
88
commentDescriptions ?: boolean ,
90
89
} ;
91
90
92
- function buildWrappedType (
93
- innerType : GraphQLType ,
94
- inputTypeNode : TypeNode ,
95
- ) : GraphQLType {
96
- if ( inputTypeNode . kind === Kind . LIST_TYPE ) {
97
- return GraphQLList ( buildWrappedType ( innerType , inputTypeNode . type ) ) ;
98
- }
99
- if ( inputTypeNode . kind === Kind . NON_NULL_TYPE ) {
100
- const wrappedType = buildWrappedType ( innerType , inputTypeNode . type ) ;
101
- return GraphQLNonNull ( assertNullableType ( wrappedType ) ) ;
102
- }
103
- return innerType ;
104
- }
105
-
106
- function getNamedTypeNode ( typeNode : TypeNode ) : NamedTypeNode {
107
- let namedType = typeNode ;
108
- while (
109
- namedType . kind === Kind . LIST_TYPE ||
110
- namedType . kind === Kind . NON_NULL_TYPE
111
- ) {
112
- namedType = namedType . type ;
113
- }
114
- return namedType ;
115
- }
116
-
117
91
/**
118
92
* This takes the ast of a schema document produced by the parse function in
119
93
* src/language/parser.js.
@@ -187,7 +161,6 @@ export function buildASTSchema(
187
161
} ,
188
162
) ;
189
163
190
- const types = definitionBuilder . buildTypes ( typeDefs ) ;
191
164
const directives = directiveDefs . map ( def =>
192
165
definitionBuilder . buildDirective ( def ) ,
193
166
) ;
@@ -218,7 +191,7 @@ export function buildASTSchema(
218
191
subscription : operationTypes . subscription
219
192
? ( definitionBuilder . buildType ( operationTypes . subscription ) : any )
220
193
: null ,
221
- types,
194
+ types : typeDefs . map ( node => definitionBuilder . buildType ( node ) ) ,
222
195
directives,
223
196
astNode : schemaDef ,
224
197
assumeValid : options && options . assumeValid ,
@@ -268,12 +241,6 @@ export class ASTDefinitionBuilder {
268
241
) ;
269
242
}
270
243
271
- buildTypes (
272
- nodes : $ReadOnlyArray < NamedTypeNode | TypeDefinitionNode > ,
273
- ) : Array < GraphQLNamedType > {
274
- return nodes . map ( node => this . buildType ( node ) ) ;
275
- }
276
-
277
244
buildType ( node : NamedTypeNode | TypeDefinitionNode ) : GraphQLNamedType {
278
245
const typeName = node . name . value ;
279
246
if ( ! this . _cache [ typeName ] ) {
@@ -290,8 +257,16 @@ export class ASTDefinitionBuilder {
290
257
}
291
258
292
259
_buildWrappedType ( typeNode : TypeNode ) : GraphQLType {
293
- const typeDef = this . buildType ( getNamedTypeNode ( typeNode ) ) ;
294
- return buildWrappedType ( typeDef , typeNode ) ;
260
+ if ( typeNode . kind === Kind . LIST_TYPE ) {
261
+ return GraphQLList ( this . _buildWrappedType ( typeNode . type ) ) ;
262
+ }
263
+ if ( typeNode . kind === Kind . NON_NULL_TYPE ) {
264
+ return GraphQLNonNull (
265
+ // Note: GraphQLNonNull constructor validates this type
266
+ ( this . _buildWrappedType ( typeNode . type ) : any ) ,
267
+ ) ;
268
+ }
269
+ return this . buildType ( typeNode ) ;
295
270
}
296
271
297
272
buildDirective ( directiveNode : DirectiveDefinitionNode ) : GraphQLDirective {
@@ -363,16 +338,17 @@ export class ASTDefinitionBuilder {
363
338
}
364
339
365
340
_makeTypeDef ( def : ObjectTypeDefinitionNode ) {
366
- const typeName = def . name . value ;
367
- const interfaces = def . interfaces ;
341
+ const interfaces : ?$ReadOnlyArray < NamedTypeNode > = def.interfaces;
368
342
return new GraphQLObjectType({
369
- name : typeName ,
343
+ name : def . name . value ,
370
344
description : getDescription ( def , this . _options ) ,
371
345
fields : ( ) => this . _makeFieldDefMap ( def ) ,
372
346
// Note: While this could make early assertions to get the correctly
373
347
// typed values, that would throw immediately while type system
374
348
// validation with validateSchema() will produce more actionable results.
375
- interfaces : interfaces ? ( ) => ( this . buildTypes ( interfaces ) : any ) : [ ] ,
349
+ interfaces : interfaces
350
+ ? ( ) => interfaces . map ( ref => ( this . buildType ( ref ) : any ) )
351
+ : [ ] ,
376
352
astNode : def ,
377
353
} );
378
354
}
@@ -426,13 +402,14 @@ export class ASTDefinitionBuilder {
426
402
}
427
403
428
404
_makeUnionDef(def: UnionTypeDefinitionNode) {
405
+ const types : ?$ReadOnlyArray < NamedTypeNode > = def . types ;
429
406
return new GraphQLUnionType ( {
430
407
name : def . name . value ,
431
408
description : getDescription ( def , this . _options ) ,
432
409
// Note: While this could make assertions to get the correctly typed
433
410
// values below, that would throw immediately while type system
434
411
// validation with validateSchema() will produce more actionable results.
435
- types : def . types ? ( this . buildTypes ( def . types ) : any ) : [ ] ,
412
+ types : types ? ( ) => types . map ( ref => ( this . buildType ( ref ) : any ) ) : [ ] ,
436
413
astNode : def ,
437
414
} ) ;
438
415
}
0 commit comments