diff --git a/executor.go b/executor.go index 947a25ec..2deb562c 100644 --- a/executor.go +++ b/executor.go @@ -727,6 +727,9 @@ func completeLeafValue(returnType Leaf, result interface{}) interface{} { // completeListValue complete a list value by completing each item in the list with the inner type func completeListValue(eCtx *executionContext, returnType *List, fieldASTs []*ast.Field, info ResolveInfo, path *responsePath, result interface{}) interface{} { resultVal := reflect.ValueOf(result) + if resultVal.Kind() == reflect.Ptr { + resultVal = resultVal.Elem() + } parentTypeName := "" if info.ParentType != nil { parentTypeName = info.ParentType.Name() diff --git a/lists_test.go b/lists_test.go index 7842d38d..94192ad6 100644 --- a/lists_test.go +++ b/lists_test.go @@ -899,3 +899,17 @@ func TestLists_ValueMayBeNilPointer(t *testing.T) { t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result)) } } + +func TestLists_NullableListOfInt_ReturnsNull(t *testing.T) { + ttype := graphql.NewList(graphql.Int) + type dataType *[]int + var data dataType + expected := &graphql.Result{ + Data: map[string]interface{}{ + "nest": map[string]interface{}{ + "test": nil, + }, + }, + } + checkList(t, ttype, data, expected) +} diff --git a/union_interface_test.go b/union_interface_test.go index ca9d12dc..8f850d60 100644 --- a/union_interface_test.go +++ b/union_interface_test.go @@ -627,13 +627,8 @@ func TestUnionIntersectionTypes_ValueMayBeNilPointer(t *testing.T) { expected := &graphql.Result{ Data: map[string]interface{}{ "query": map[string]interface{}{ - "pet": map[string]interface{}{ - "__typename": "Cat", - }, - "named": map[string]interface{}{ - "__typename": "Cat", - "name": nil, - }, + "pet": nil, + "named": nil, }}, } result := g(t, graphql.Params{ diff --git a/values.go b/values.go index a68866e1..06c08af6 100644 --- a/values.go +++ b/values.go @@ -302,6 +302,9 @@ func isNullish(src interface{}) bool { } value := reflect.ValueOf(src) if value.Kind() == reflect.Ptr { + if value.IsNil() { + return true + } value = value.Elem() } switch value.Kind() { @@ -324,6 +327,9 @@ func isIterable(src interface{}) bool { return false } t := reflect.TypeOf(src) + if t.Kind() == reflect.Ptr { + t = t.Elem() + } return t.Kind() == reflect.Slice || t.Kind() == reflect.Array }