From 2d22f8bc108bac6d5def6aa0b1e497e9c57d40d7 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Mon, 18 May 2020 07:50:33 -0400 Subject: [PATCH] simplify handleNull this function after prior refactoring was recursively passing along arugments without actually ever using them --- packages/delegate/src/proxiedResult.ts | 4 ++-- packages/delegate/src/results/handleList.ts | 5 +---- packages/delegate/src/results/handleNull.ts | 12 ++++-------- packages/delegate/src/results/handleResult.ts | 3 +-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/packages/delegate/src/proxiedResult.ts b/packages/delegate/src/proxiedResult.ts index 065877cfbb0..fccd6de89e4 100644 --- a/packages/delegate/src/proxiedResult.ts +++ b/packages/delegate/src/proxiedResult.ts @@ -1,4 +1,4 @@ -import { GraphQLError, responsePathAsArray, GraphQLResolveInfo } from 'graphql'; +import { GraphQLError, GraphQLResolveInfo } from 'graphql'; import { mergeDeep, ERROR_SYMBOL, relocatedError, setErrors, getErrors } from '@graphql-tools/utils'; @@ -22,7 +22,7 @@ export function unwrapResult(parent: any, info: GraphQLResolveInfo, path: Array< const object = newParent[responseKey]; if (object == null) { - return handleNull(info.fieldNodes, responsePathAsArray(info.path), errors); + return handleNull(errors); } setErrors( diff --git a/packages/delegate/src/results/handleList.ts b/packages/delegate/src/results/handleList.ts index 673a3a125eb..3641e90aea8 100644 --- a/packages/delegate/src/results/handleList.ts +++ b/packages/delegate/src/results/handleList.ts @@ -5,7 +5,6 @@ import { GraphQLResolveInfo, getNullableType, GraphQLType, - responsePathAsArray, isLeafType, isCompositeType, isListType, @@ -32,7 +31,6 @@ export function handleList( handleListMember( getNullableType(type.ofType), listMember, - index, index in childErrors ? childErrors[index] : [], subschema, context, @@ -45,7 +43,6 @@ export function handleList( function handleListMember( type: GraphQLType, listMember: any, - index: number, errors: ReadonlyArray, subschema: GraphQLSchema | SubschemaConfig, context: Record, @@ -53,7 +50,7 @@ function handleListMember( skipTypeMerging?: boolean ): any { if (listMember == null) { - return handleNull(info.fieldNodes, [...responsePathAsArray(info.path), index], errors); + return handleNull(errors); } if (isLeafType(type)) { diff --git a/packages/delegate/src/results/handleNull.ts b/packages/delegate/src/results/handleNull.ts index 575283f8e51..cfea57daf00 100644 --- a/packages/delegate/src/results/handleNull.ts +++ b/packages/delegate/src/results/handleNull.ts @@ -1,12 +1,8 @@ -import { FieldNode, GraphQLError } from 'graphql'; +import { GraphQLError } from 'graphql'; import { getErrorsByPathSegment, CombinedError } from '@graphql-tools/utils'; -export function handleNull( - fieldNodes: ReadonlyArray, - path: Array, - errors: ReadonlyArray -) { +export function handleNull(errors: ReadonlyArray) { if (errors.length) { if (errors.some(error => !error.path || error.path.length < 2)) { if (errors.length > 1) { @@ -20,7 +16,7 @@ export function handleNull( const result = {}; Object.keys(childErrors).forEach(pathSegment => { - result[pathSegment] = handleNull(fieldNodes, [...path, pathSegment], childErrors[pathSegment]); + result[pathSegment] = handleNull(childErrors[pathSegment]); }); return result; @@ -30,7 +26,7 @@ export function handleNull( const result: Array = []; Object.keys(childErrors).forEach(pathSegment => { - result.push(handleNull(fieldNodes, [...path, parseInt(pathSegment, 10)], childErrors[pathSegment])); + result.push(handleNull(childErrors[pathSegment])); }); return result; diff --git a/packages/delegate/src/results/handleResult.ts b/packages/delegate/src/results/handleResult.ts index d895e6f039f..76cc53e5172 100644 --- a/packages/delegate/src/results/handleResult.ts +++ b/packages/delegate/src/results/handleResult.ts @@ -1,6 +1,5 @@ import { GraphQLResolveInfo, - responsePathAsArray, getNullableType, isCompositeType, isLeafType, @@ -27,7 +26,7 @@ export function handleResult( const type = getNullableType(returnType); if (result == null) { - return handleNull(info?.fieldNodes, responsePathAsArray(info?.path), errors); + return handleNull(errors); } if (isLeafType(type)) {