Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify handleNull #1483

Merged
merged 1 commit into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/delegate/src/proxiedResult.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions packages/delegate/src/results/handleList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
GraphQLResolveInfo,
getNullableType,
GraphQLType,
responsePathAsArray,
isLeafType,
isCompositeType,
isListType,
Expand All @@ -32,7 +31,6 @@ export function handleList(
handleListMember(
getNullableType(type.ofType),
listMember,
index,
index in childErrors ? childErrors[index] : [],
subschema,
context,
Expand All @@ -45,15 +43,14 @@ export function handleList(
function handleListMember(
type: GraphQLType,
listMember: any,
index: number,
errors: ReadonlyArray<GraphQLError>,
subschema: GraphQLSchema | SubschemaConfig,
context: Record<string, any>,
info: GraphQLResolveInfo,
skipTypeMerging?: boolean
): any {
if (listMember == null) {
return handleNull(info.fieldNodes, [...responsePathAsArray(info.path), index], errors);
return handleNull(errors);
}

if (isLeafType(type)) {
Expand Down
12 changes: 4 additions & 8 deletions packages/delegate/src/results/handleNull.ts
Original file line number Diff line number Diff line change
@@ -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<FieldNode>,
path: Array<string | number>,
errors: ReadonlyArray<GraphQLError>
) {
export function handleNull(errors: ReadonlyArray<GraphQLError>) {
if (errors.length) {
if (errors.some(error => !error.path || error.path.length < 2)) {
if (errors.length > 1) {
Expand All @@ -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;
Expand All @@ -30,7 +26,7 @@ export function handleNull(

const result: Array<any> = [];
Object.keys(childErrors).forEach(pathSegment => {
result.push(handleNull(fieldNodes, [...path, parseInt(pathSegment, 10)], childErrors[pathSegment]));
result.push(handleNull(childErrors[pathSegment]));
});

return result;
Expand Down
3 changes: 1 addition & 2 deletions packages/delegate/src/results/handleResult.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
GraphQLResolveInfo,
responsePathAsArray,
getNullableType,
isCompositeType,
isLeafType,
Expand All @@ -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)) {
Expand Down