diff --git a/graphql_test.go b/graphql_test.go index f906f14b..a6770c2c 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -1544,6 +1544,24 @@ func (r *testBadEnumCharacterResolver) AppearsIn() []string { return []string{"STAR_TREK"} } +func TestUnknownType(t *testing.T) { + gqltesting.RunTest(t, &gqltesting.Test{ + Schema: starwarsSchema, + Query: ` + query TypeInfo { + __type(name: "unknown-type") { + name + } + } + `, + ExpectedResult: ` + { + "__type": null + } + `, + }) +} + func TestEnums(t *testing.T) { gqltesting.RunTests(t, []*gqltesting.Test{ // Valid input enum supplied in query text diff --git a/internal/exec/selected/selected.go b/internal/exec/selected/selected.go index 868dc1e9..f5b37405 100644 --- a/internal/exec/selected/selected.go +++ b/internal/exec/selected/selected.go @@ -107,9 +107,10 @@ func applySelectionSet(r *Request, s *resolvable.Schema, e *resolvable.Object, s return nil } + var resolvedType *introspection.Type t, ok := r.Schema.Types[v.String()] - if !ok { - return nil + if ok { + resolvedType = introspection.WrapType(t) } flattenedSels = append(flattenedSels, &SchemaField{ @@ -117,7 +118,7 @@ func applySelectionSet(r *Request, s *resolvable.Schema, e *resolvable.Object, s Alias: field.Alias.Name, Sels: applySelectionSet(r, s, s.Meta.Type, field.SelectionSet), Async: true, - FixedResult: reflect.ValueOf(introspection.WrapType(t)), + FixedResult: reflect.ValueOf(resolvedType), }) }