@@ -36,10 +36,6 @@ import objectValues from '../jsutils/objectValues';
3636import { GraphQLError } from '../error/GraphQLError' ;
3737import type {
3838 ASTNode ,
39- ObjectTypeDefinitionNode ,
40- ObjectTypeExtensionNode ,
41- InterfaceTypeDefinitionNode ,
42- InterfaceTypeExtensionNode ,
4339 FieldDefinitionNode ,
4440 EnumValueDefinitionNode ,
4541 InputValueDefinitionNode ,
@@ -283,7 +279,7 @@ function validateFields(
283279 if ( fields . length === 0 ) {
284280 context . reportError (
285281 `Type ${ type . name } must define one or more fields.` ,
286- getAllObjectOrInterfaceNodes ( type ) ,
282+ getAllNodes ( type ) ,
287283 ) ;
288284 }
289285
@@ -578,29 +574,16 @@ function validateInputFields(
578574 } ) ;
579575}
580576
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 || [ ] ;
604587}
605588
606589function getImplementsInterfaceNode (
@@ -615,7 +598,7 @@ function getAllImplementsInterfaceNodes(
615598 iface : GraphQLInterfaceType ,
616599) : $ReadOnlyArray < NamedTypeNode > {
617600 const implementsNodes = [ ] ;
618- const astNodes = getAllObjectNodes ( type ) ;
601+ const astNodes = getAllNodes ( type ) ;
619602 for ( let i = 0 ; i < astNodes . length ; i ++ ) {
620603 const astNode = astNodes [ i ] ;
621604 if ( astNode && astNode . interfaces ) {
@@ -641,7 +624,7 @@ function getAllFieldNodes(
641624 fieldName : string ,
642625) : $ReadOnlyArray < FieldDefinitionNode > {
643626 const fieldNodes = [ ] ;
644- const astNodes = getAllObjectOrInterfaceNodes ( type ) ;
627+ const astNodes = getAllNodes ( type ) ;
645628 for ( let i = 0 ; i < astNodes . length ; i ++ ) {
646629 const astNode = astNodes [ i ] ;
647630 if ( astNode && astNode . fields ) {
0 commit comments