@@ -36,10 +36,6 @@ import objectValues from '../jsutils/objectValues';
36
36
import { GraphQLError } from '../error/GraphQLError' ;
37
37
import type {
38
38
ASTNode ,
39
- ObjectTypeDefinitionNode ,
40
- ObjectTypeExtensionNode ,
41
- InterfaceTypeDefinitionNode ,
42
- InterfaceTypeExtensionNode ,
43
39
FieldDefinitionNode ,
44
40
EnumValueDefinitionNode ,
45
41
InputValueDefinitionNode ,
@@ -283,7 +279,7 @@ function validateFields(
283
279
if ( fields . length === 0 ) {
284
280
context . reportError (
285
281
`Type ${ type . name } must define one or more fields.` ,
286
- getAllObjectOrInterfaceNodes ( type ) ,
282
+ getAllNodes ( type ) ,
287
283
) ;
288
284
}
289
285
@@ -578,29 +574,16 @@ function validateInputFields(
578
574
} ) ;
579
575
}
580
576
581
- function getAllObjectNodes (
582
- type : GraphQLObjectType ,
583
- ) : $ReadOnlyArray < ObjectTypeDefinitionNode | ObjectTypeExtensionNode > {
584
- return type . astNode
585
- ? type . extensionASTNodes
586
- ? [ type . astNode ] . concat ( type . extensionASTNodes )
587
- : [ type . astNode ]
588
- : type . extensionASTNodes || [ ] ;
589
- }
590
-
591
- function getAllObjectOrInterfaceNodes (
592
- type : GraphQLObjectType | GraphQLInterfaceType ,
593
- ) : $ReadOnlyArray <
594
- | ObjectTypeDefinitionNode
595
- | ObjectTypeExtensionNode
596
- | InterfaceTypeDefinitionNode
597
- | InterfaceTypeExtensionNode ,
598
- > {
599
- return type . astNode
600
- ? type . extensionASTNodes
601
- ? [ type . astNode ] . concat ( type . extensionASTNodes )
602
- : [ type . astNode ]
603
- : type . extensionASTNodes || [ ] ;
577
+ function getAllNodes < T : ASTNode , K : ASTNode > ( object : {
578
+ + astNode : ?T ,
579
+ + extensionASTNodes ?: ?$ReadOnlyArray < K > ,
580
+ } ) : $ReadOnlyArray < T | K > {
581
+ const { astNode, extensionASTNodes } = object ;
582
+ return astNode
583
+ ? extensionASTNodes
584
+ ? [ astNode ] . concat ( extensionASTNodes )
585
+ : [ astNode ]
586
+ : extensionASTNodes || [ ] ;
604
587
}
605
588
606
589
function getImplementsInterfaceNode (
@@ -615,7 +598,7 @@ function getAllImplementsInterfaceNodes(
615
598
iface : GraphQLInterfaceType ,
616
599
) : $ReadOnlyArray < NamedTypeNode > {
617
600
const implementsNodes = [ ] ;
618
- const astNodes = getAllObjectNodes ( type ) ;
601
+ const astNodes = getAllNodes ( type ) ;
619
602
for ( let i = 0 ; i < astNodes . length ; i ++ ) {
620
603
const astNode = astNodes [ i ] ;
621
604
if ( astNode && astNode . interfaces ) {
@@ -641,7 +624,7 @@ function getAllFieldNodes(
641
624
fieldName : string ,
642
625
) : $ReadOnlyArray < FieldDefinitionNode > {
643
626
const fieldNodes = [ ] ;
644
- const astNodes = getAllObjectOrInterfaceNodes ( type ) ;
627
+ const astNodes = getAllNodes ( type ) ;
645
628
for ( let i = 0 ; i < astNodes . length ; i ++ ) {
646
629
const astNode = astNodes [ i ] ;
647
630
if ( astNode && astNode . fields ) {
0 commit comments