Skip to content

Commit e892575

Browse files
authored
Fix __type queries sometimes not returning data (#540)
* Fix __type queries sometimes not returning data If the queried type was not defined it would return an empty data section instead of `__type: null` Fixes #539
1 parent 0135d51 commit e892575

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

graphql_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,24 @@ func (r *testBadEnumCharacterResolver) AppearsIn() []string {
15441544
return []string{"STAR_TREK"}
15451545
}
15461546

1547+
func TestUnknownType(t *testing.T) {
1548+
gqltesting.RunTest(t, &gqltesting.Test{
1549+
Schema: starwarsSchema,
1550+
Query: `
1551+
query TypeInfo {
1552+
__type(name: "unknown-type") {
1553+
name
1554+
}
1555+
}
1556+
`,
1557+
ExpectedResult: `
1558+
{
1559+
"__type": null
1560+
}
1561+
`,
1562+
})
1563+
}
1564+
15471565
func TestEnums(t *testing.T) {
15481566
gqltesting.RunTests(t, []*gqltesting.Test{
15491567
// Valid input enum supplied in query text

internal/exec/selected/selected.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,18 @@ func applySelectionSet(r *Request, s *resolvable.Schema, e *resolvable.Object, s
107107
return nil
108108
}
109109

110+
var resolvedType *introspection.Type
110111
t, ok := r.Schema.Types[v.String()]
111-
if !ok {
112-
return nil
112+
if ok {
113+
resolvedType = introspection.WrapType(t)
113114
}
114115

115116
flattenedSels = append(flattenedSels, &SchemaField{
116117
Field: s.Meta.FieldType,
117118
Alias: field.Alias.Name,
118119
Sels: applySelectionSet(r, s, s.Meta.Type, field.SelectionSet),
119120
Async: true,
120-
FixedResult: reflect.ValueOf(introspection.WrapType(t)),
121+
FixedResult: reflect.ValueOf(resolvedType),
121122
})
122123
}
123124

0 commit comments

Comments
 (0)