From 0438a81aa83d43f561003613ffdd99a368b027bf Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 21 Feb 2021 16:34:56 +0200 Subject: [PATCH] validateSchema: inline 'getAllNodes' function --- src/type/validate.js | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/type/validate.js b/src/type/validate.js index 664c57332a..52a7051e5e 100644 --- a/src/type/validate.js +++ b/src/type/validate.js @@ -143,13 +143,10 @@ function getOperationTypeNode( schema: GraphQLSchema, operation: OperationTypeNode, ): ?ASTNode { - const operationNodes = getAllSubNodes(schema, (node) => node.operationTypes); - for (const node of operationNodes) { - if (node.operation === operation) { - return node.type; - } - } - return undefined; + // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') + return getAllNodes(schema) + .flatMap((schemaNode) => schemaNode.operationTypes ?? []) + .find((operationNode) => operationNode.operation === operation)?.type; } function validateDirectives(context: SchemaValidationContext): void { @@ -626,34 +623,24 @@ function getAllNodes( : extensionASTNodes ?? []; } -function getAllSubNodes( - object: SDLDefinedObject, - getter: (T | K) => ?(L | $ReadOnlyArray), -): $ReadOnlyArray { - let subNodes = []; - for (const node of getAllNodes(object)) { - // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') - subNodes = subNodes.concat(getter(node) ?? []); - } - return subNodes; -} - function getAllImplementsInterfaceNodes( type: GraphQLObjectType | GraphQLInterfaceType, iface: GraphQLInterfaceType, ): $ReadOnlyArray { - return getAllSubNodes(type, (typeNode) => typeNode.interfaces).filter( - (ifaceNode) => ifaceNode.name.value === iface.name, - ); + // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') + return getAllNodes(type) + .flatMap((typeNode) => typeNode.interfaces ?? []) + .filter((ifaceNode) => ifaceNode.name.value === iface.name); } function getUnionMemberTypeNodes( union: GraphQLUnionType, typeName: string, ): ?$ReadOnlyArray { - return getAllSubNodes(union, (unionNode) => unionNode.types).filter( - (typeNode) => typeNode.name.value === typeName, - ); + // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') + return getAllNodes(union) + .flatMap((unionNode) => unionNode.types ?? []) + .filter((typeNode) => typeNode.name.value === typeName); } function getDeprecatedDirectiveNode(