Skip to content

Commit 6131ddf

Browse files
authored
Merge branch 'master' into deferred-thunks
2 parents a7f8140 + ef7caf8 commit 6131ddf

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

executor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ func completeLeafValue(returnType Leaf, result interface{}) interface{} {
788788
// completeListValue complete a list value by completing each item in the list with the inner type
789789
func completeListValue(eCtx *executionContext, returnType *List, fieldASTs []*ast.Field, info ResolveInfo, path *responsePath, result interface{}) interface{} {
790790
resultVal := reflect.ValueOf(result)
791+
if resultVal.Kind() == reflect.Ptr {
792+
resultVal = resultVal.Elem()
793+
}
791794
parentTypeName := ""
792795
if info.ParentType != nil {
793796
parentTypeName = info.ParentType.Name()

lists_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,3 +913,17 @@ func TestLists_ValueMayBeNilPointer(t *testing.T) {
913913
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
914914
}
915915
}
916+
917+
func TestLists_NullableListOfInt_ReturnsNull(t *testing.T) {
918+
ttype := graphql.NewList(graphql.Int)
919+
type dataType *[]int
920+
var data dataType
921+
expected := &graphql.Result{
922+
Data: map[string]interface{}{
923+
"nest": map[string]interface{}{
924+
"test": nil,
925+
},
926+
},
927+
}
928+
checkList(t, ttype, data, expected)
929+
}

union_interface_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,8 @@ func TestUnionIntersectionTypes_ValueMayBeNilPointer(t *testing.T) {
627627
expected := &graphql.Result{
628628
Data: map[string]interface{}{
629629
"query": map[string]interface{}{
630-
"pet": map[string]interface{}{
631-
"__typename": "Cat",
632-
},
633-
"named": map[string]interface{}{
634-
"__typename": "Cat",
635-
"name": nil,
636-
},
630+
"pet": nil,
631+
"named": nil,
637632
}},
638633
}
639634
result := g(t, graphql.Params{

values.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ func isNullish(src interface{}) bool {
302302
}
303303
value := reflect.ValueOf(src)
304304
if value.Kind() == reflect.Ptr {
305+
if value.IsNil() {
306+
return true
307+
}
305308
value = value.Elem()
306309
}
307310
switch value.Kind() {
@@ -324,6 +327,9 @@ func isIterable(src interface{}) bool {
324327
return false
325328
}
326329
t := reflect.TypeOf(src)
330+
if t.Kind() == reflect.Ptr {
331+
t = t.Elem()
332+
}
327333
return t.Kind() == reflect.Slice || t.Kind() == reflect.Array
328334
}
329335

0 commit comments

Comments
 (0)