@@ -47,7 +47,6 @@ import type {
47
47
} from '../type/definition' ;
48
48
49
49
import {
50
- assertNullableType ,
51
50
GraphQLScalarType ,
52
51
GraphQLObjectType ,
53
52
GraphQLInterfaceType ,
@@ -92,31 +91,6 @@ export type BuildSchemaOptions = {
92
91
commentDescriptions ?: boolean ,
93
92
} ;
94
93
95
- function buildWrappedType (
96
- innerType : GraphQLType ,
97
- inputTypeNode : TypeNode ,
98
- ) : GraphQLType {
99
- if ( inputTypeNode . kind === Kind . LIST_TYPE ) {
100
- return GraphQLList ( buildWrappedType ( innerType , inputTypeNode . type ) ) ;
101
- }
102
- if ( inputTypeNode . kind === Kind . NON_NULL_TYPE ) {
103
- const wrappedType = buildWrappedType ( innerType , inputTypeNode . type ) ;
104
- return GraphQLNonNull ( assertNullableType ( wrappedType ) ) ;
105
- }
106
- return innerType ;
107
- }
108
-
109
- function getNamedTypeNode ( typeNode : TypeNode ) : NamedTypeNode {
110
- let namedType = typeNode ;
111
- while (
112
- namedType . kind === Kind . LIST_TYPE ||
113
- namedType . kind === Kind . NON_NULL_TYPE
114
- ) {
115
- namedType = namedType . type ;
116
- }
117
- return namedType ;
118
- }
119
-
120
94
/**
121
95
* This takes the ast of a schema document produced by the parse function in
122
96
* src/language/parser.js.
@@ -190,7 +164,6 @@ export function buildASTSchema(
190
164
} ,
191
165
) ;
192
166
193
- const types = definitionBuilder . buildTypes ( typeDefs ) ;
194
167
const directives = directiveDefs . map ( def =>
195
168
definitionBuilder . buildDirective ( def ) ,
196
169
) ;
@@ -221,7 +194,7 @@ export function buildASTSchema(
221
194
subscription : operationTypes . subscription
222
195
? ( definitionBuilder . buildType ( operationTypes . subscription ) : any )
223
196
: null ,
224
- types,
197
+ types : typeDefs . map ( node => definitionBuilder . buildType ( node ) ) ,
225
198
directives,
226
199
astNode : schemaDef ,
227
200
assumeValid : options && options . assumeValid ,
@@ -271,9 +244,7 @@ export class ASTDefinitionBuilder {
271
244
) ;
272
245
}
273
246
274
- buildTypes (
275
- nodes : $ReadOnlyArray < NamedTypeNode | TypeDefinitionNode > ,
276
- ) : Array < GraphQLNamedType > {
247
+ buildTypes ( nodes : $ReadOnlyArray < NamedTypeNode > ) : Array < GraphQLNamedType > {
277
248
return nodes . map ( node => this . buildType ( node ) ) ;
278
249
}
279
250
@@ -293,8 +264,16 @@ export class ASTDefinitionBuilder {
293
264
}
294
265
295
266
_buildWrappedType ( typeNode : TypeNode ) : GraphQLType {
296
- const typeDef = this . buildType ( getNamedTypeNode ( typeNode ) ) ;
297
- return buildWrappedType ( typeDef , typeNode ) ;
267
+ if ( typeNode . kind === Kind . LIST_TYPE ) {
268
+ return GraphQLList ( this . _buildWrappedType ( typeNode . type ) ) ;
269
+ }
270
+ if ( typeNode . kind === Kind . NON_NULL_TYPE ) {
271
+ return GraphQLNonNull (
272
+ // Note: GraphQLNonNull constructor validates this type
273
+ ( this . _buildWrappedType ( typeNode . type ) : any ) ,
274
+ ) ;
275
+ }
276
+ return this . buildType ( typeNode ) ;
298
277
}
299
278
300
279
buildDirective ( directiveNode : DirectiveDefinitionNode ) : GraphQLDirective {
@@ -366,10 +345,9 @@ export class ASTDefinitionBuilder {
366
345
}
367
346
368
347
_makeTypeDef ( def : ObjectTypeDefinitionNode ) {
369
- const typeName = def . name . value ;
370
348
const interfaces = def . interfaces ;
371
349
return new GraphQLObjectType ( {
372
- name : typeName ,
350
+ name : def . name . value ,
373
351
description : getDescription ( def , this . _options ) ,
374
352
fields : ( ) => this . _makeFieldDefMap ( def ) ,
375
353
// Note: While this could make early assertions to get the correctly
0 commit comments