Skip to content

Commit 21dfa5d

Browse files
committed
Added test for Enum nil pointer handling
1 parent 4c649e3 commit 21dfa5d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

enum_type_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,42 @@ func TestTypeSystem_EnumValues_EnumValueMayBePointer(t *testing.T) {
421421
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
422422
}
423423
}
424+
425+
func TestTypeSystem_EnumValues_EnumValueMayBeNilPointer(t *testing.T) {
426+
var enumTypeTestSchema, _ = graphql.NewSchema(graphql.SchemaConfig{
427+
Query: graphql.NewObject(graphql.ObjectConfig{
428+
Name: "Query",
429+
Fields: graphql.Fields{
430+
"query": &graphql.Field{
431+
Type: graphql.NewObject(graphql.ObjectConfig{
432+
Name: "query",
433+
Fields: graphql.Fields{
434+
"color": &graphql.Field{
435+
Type: enumTypeTestColorType,
436+
},
437+
},
438+
}),
439+
Resolve: func(_ graphql.ResolveParams) (interface{}, error) {
440+
return struct {
441+
Color *int `graphql:"color"`
442+
}{nil}, nil
443+
},
444+
},
445+
},
446+
}),
447+
})
448+
query := "{ query { color } }"
449+
expected := &graphql.Result{
450+
Data: map[string]interface{}{
451+
"query": map[string]interface{}{
452+
"color": nil,
453+
}},
454+
}
455+
result := g(t, graphql.Params{
456+
Schema: enumTypeTestSchema,
457+
RequestString: query,
458+
})
459+
if !reflect.DeepEqual(expected, result) {
460+
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
461+
}
462+
}

0 commit comments

Comments
 (0)