From 9eea47fcc3721d2f0d5918e171c4d73ac2a4b9e3 Mon Sep 17 00:00:00 2001 From: carmelid Date: Tue, 16 Jul 2019 16:33:28 +0200 Subject: [PATCH] fix: default merged resolver behavior for nullable fields --- src/stitching/defaultMergedResolver.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/stitching/defaultMergedResolver.ts b/src/stitching/defaultMergedResolver.ts index cbf754a03a8..5e5ca3822ea 100644 --- a/src/stitching/defaultMergedResolver.ts +++ b/src/stitching/defaultMergedResolver.ts @@ -1,4 +1,4 @@ -import { GraphQLFieldResolver, responsePathAsArray } from 'graphql'; +import { GraphQLFieldResolver, GraphQLNonNull, responsePathAsArray } from 'graphql'; import { locatedError } from 'graphql/error'; import { getErrorsFromParent, annotateWithChildrenErrors } from './errors'; import { getResponseKeyFromInfo } from './getResponseKeyFromInfo'; @@ -20,7 +20,8 @@ const defaultMergedResolver: GraphQLFieldResolver = (parent, args, con let result = parent[responseKey]; - if (result == null) { + // Only replace the aliased result with the parent result if the field is non-nullable + if (result == null && info.returnType instanceof GraphQLNonNull) { result = parent[info.fieldName]; }