From f23e3c8a808b88c1c2db2d889069639885875828 Mon Sep 17 00:00:00 2001 From: Jared Breeden Date: Fri, 27 Mar 2020 12:04:25 -0400 Subject: [PATCH] Fix bug with null result for federated objects --- execute.go | 10 ++++++++++ http.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/execute.go b/execute.go index 3e6942e..9a79218 100644 --- a/execute.go +++ b/execute.go @@ -368,6 +368,16 @@ func executorFindInsertionPoints(resultLock *sync.Mutex, targetPoints []string, // get the type of the object in question selectionType := foundSelection.Definition.Type + if rootValue == nil { + if selectionType.NonNull { + err := fmt.Errorf("Received null for required field: %v", foundSelection.Name) + log.Warn(err) + return nil, err + } else { + return nil, nil + } + } + // if the type is a list if selectionType.Elem != nil { log.Debug("Selection should be a list") diff --git a/http.go b/http.go index 84cccbd..00ae677 100644 --- a/http.go +++ b/http.go @@ -205,7 +205,7 @@ func (g *Gateway) GraphQLHandler(w http.ResponseWriter, r *http.Request) { // fire the query with the request context passed through to execution result, err = g.Execute(requestContext, plan) if err != nil { - results = append(results, formatErrorsWithCode(nil, err, "INTERNAL_SERVER_ERROR")) + results = append(results, formatErrorsWithCode(result, err, "INTERNAL_SERVER_ERROR")) continue }