@@ -433,10 +433,11 @@ export function extendSchemaImpl(
433
433
// validation with validateSchema() will produce more actionable results.
434
434
const opTypes : any = { } ;
435
435
for ( const node of nodes ) {
436
- if ( node . operationTypes != null ) {
437
- for ( const operationType of node . operationTypes ) {
438
- opTypes [ operationType . operation ] = getNamedType ( operationType . type ) ;
439
- }
436
+ /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
437
+ const operationTypesNodes = node . operationTypes || [ ] ;
438
+
439
+ for ( const operationType of operationTypesNodes ) {
440
+ opTypes [ operationType . operation ] = getNamedType ( operationType . type ) ;
440
441
}
441
442
}
442
443
return opTypes ;
@@ -487,19 +488,20 @@ export function extendSchemaImpl(
487
488
) : GraphQLFieldConfigMap < mixed , mixed > {
488
489
const fieldConfigMap = Object . create ( null ) ;
489
490
for ( const node of nodes ) {
490
- if ( node . fields != null ) {
491
- for ( const field of node . fields ) {
492
- fieldConfigMap [ field . name . value ] = {
493
- // Note: While this could make assertions to get the correctly typed
494
- // value, that would throw immediately while type system validation
495
- // with validateSchema() will produce more actionable results.
496
- type : ( getWrappedType ( field . type ) : any ) ,
497
- description : getDescription ( field , options ) ,
498
- args : buildArgumentMap ( field . arguments ) ,
499
- deprecationReason : getDeprecationReason ( field ) ,
500
- astNode : field ,
501
- } ;
502
- }
491
+ /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
492
+ const nodeFields = node . fields || [ ] ;
493
+
494
+ for ( const field of nodeFields ) {
495
+ fieldConfigMap [ field . name . value ] = {
496
+ // Note: While this could make assertions to get the correctly typed
497
+ // value, that would throw immediately while type system validation
498
+ // with validateSchema() will produce more actionable results.
499
+ type : ( getWrappedType ( field . type ) : any ) ,
500
+ description : getDescription ( field , options ) ,
501
+ args : buildArgumentMap ( field . arguments ) ,
502
+ deprecationReason : getDeprecationReason ( field ) ,
503
+ astNode : field ,
504
+ } ;
503
505
}
504
506
}
505
507
return fieldConfigMap ;
@@ -508,21 +510,22 @@ export function extendSchemaImpl(
508
510
function buildArgumentMap (
509
511
args : ?$ReadOnlyArray < InputValueDefinitionNode > ,
510
512
) : GraphQLFieldConfigArgumentMap {
511
- const argConfigMap = Object . create ( null ) ;
512
- if ( args != null ) {
513
- for ( const arg of args ) {
514
- // Note: While this could make assertions to get the correctly typed
515
- // value, that would throw immediately while type system validation
516
- // with validateSchema() will produce more actionable results.
517
- const type : any = getWrappedType ( arg . type ) ;
513
+ /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
514
+ const argsNodes = args || [ ] ;
518
515
519
- argConfigMap [ arg . name . value ] = {
520
- type,
521
- description : getDescription ( arg , options ) ,
522
- defaultValue : valueFromAST ( arg . defaultValue , type ) ,
523
- astNode : arg ,
524
- } ;
525
- }
516
+ const argConfigMap = Object . create ( null ) ;
517
+ for ( const arg of argsNodes ) {
518
+ // Note: While this could make assertions to get the correctly typed
519
+ // value, that would throw immediately while type system validation
520
+ // with validateSchema() will produce more actionable results.
521
+ const type : any = getWrappedType ( arg . type ) ;
522
+
523
+ argConfigMap [ arg . name . value ] = {
524
+ type,
525
+ description : getDescription ( arg , options ) ,
526
+ defaultValue : valueFromAST ( arg . defaultValue , type ) ,
527
+ astNode : arg ,
528
+ } ;
526
529
}
527
530
return argConfigMap ;
528
531
}
@@ -534,20 +537,21 @@ export function extendSchemaImpl(
534
537
) : GraphQLInputFieldConfigMap {
535
538
const inputFieldMap = Object . create ( null ) ;
536
539
for ( const node of nodes ) {
537
- if ( node . fields != null ) {
538
- for ( const field of node . fields ) {
539
- // Note: While this could make assertions to get the correctly typed
540
- // value, that would throw immediately while type system validation
541
- // with validateSchema() will produce more actionable results.
542
- const type : any = getWrappedType ( field . type ) ;
543
-
544
- inputFieldMap [ field . name . value ] = {
545
- type,
546
- description : getDescription ( field , options ) ,
547
- defaultValue : valueFromAST ( field . defaultValue , type ) ,
548
- astNode : field ,
549
- } ;
550
- }
540
+ /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
541
+ const fieldsNodes = node . fields || [ ] ;
542
+
543
+ for ( const field of fieldsNodes ) {
544
+ // Note: While this could make assertions to get the correctly typed
545
+ // value, that would throw immediately while type system validation
546
+ // with validateSchema() will produce more actionable results.
547
+ const type : any = getWrappedType ( field . type ) ;
548
+
549
+ inputFieldMap [ field . name . value ] = {
550
+ type,
551
+ description : getDescription ( field , options ) ,
552
+ defaultValue : valueFromAST ( field . defaultValue , type ) ,
553
+ astNode : field ,
554
+ } ;
551
555
}
552
556
}
553
557
return inputFieldMap ;
@@ -558,14 +562,15 @@ export function extendSchemaImpl(
558
562
) : GraphQLEnumValueConfigMap {
559
563
const enumValueMap = Object . create ( null ) ;
560
564
for ( const node of nodes ) {
561
- if ( node . values != null ) {
562
- for ( const value of node . values ) {
563
- enumValueMap [ value . name . value ] = {
564
- description : getDescription ( value , options ) ,
565
- deprecationReason : getDeprecationReason ( value ) ,
566
- astNode : value ,
567
- } ;
568
- }
565
+ /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
566
+ const valuesNodes = node . values || [ ] ;
567
+
568
+ for ( const value of valuesNodes ) {
569
+ enumValueMap [ value . name . value ] = {
570
+ description : getDescription ( value , options ) ,
571
+ deprecationReason : getDeprecationReason ( value ) ,
572
+ astNode : value ,
573
+ } ;
569
574
}
570
575
}
571
576
return enumValueMap ;
@@ -581,14 +586,15 @@ export function extendSchemaImpl(
581
586
) : Array < GraphQLInterfaceType > {
582
587
const interfaces = [ ] ;
583
588
for ( const node of nodes ) {
584
- if ( node . interfaces != null ) {
585
- for ( const type of node . interfaces ) {
586
- // Note: While this could make assertions to get the correctly typed
587
- // values below, that would throw immediately while type system
588
- // validation with validateSchema() will produce more actionable
589
- // results.
590
- interfaces . push ( ( getNamedType ( type ) : any ) ) ;
591
- }
589
+ /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
590
+ const interfacesNodes = node . interfaces || [ ] ;
591
+
592
+ for ( const type of interfacesNodes ) {
593
+ // Note: While this could make assertions to get the correctly typed
594
+ // values below, that would throw immediately while type system
595
+ // validation with validateSchema() will produce more actionable
596
+ // results.
597
+ interfaces. push ( ( getNamedType ( type ) : any ) ) ;
592
598
}
593
599
}
594
600
return interfaces ;
@@ -599,14 +605,15 @@ export function extendSchemaImpl(
599
605
) : Array < GraphQLObjectType > {
600
606
const types = [ ] ;
601
607
for ( const node of nodes ) {
602
- if ( node . types != null ) {
603
- for ( const type of node . types ) {
604
- // Note: While this could make assertions to get the correctly typed
605
- // values below, that would throw immediately while type system
606
- // validation with validateSchema() will produce more actionable
607
- // results.
608
- types . push ( ( getNamedType ( type ) : any ) ) ;
609
- }
608
+ /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
609
+ const typeNodes = node . types || [ ] ;
610
+
611
+ for ( const type of typeNodes ) {
612
+ // Note: While this could make assertions to get the correctly typed
613
+ // values below, that would throw immediately while type system
614
+ // validation with validateSchema() will produce more actionable
615
+ // results.
616
+ types. push ( ( getNamedType ( type ) : any ) ) ;
610
617
}
611
618
}
612
619
return types ;
0 commit comments