Skip to content

Commit d2656e8

Browse files
authored
Merge pull request #423 from Epsirom/master
DisableIntrospection should skip __typename
2 parents bd703c2 + 7db17b6 commit d2656e8

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

graphql_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,44 @@ func TestIntrospectionDisableIntrospection(t *testing.T) {
26142614
}
26152615
`,
26162616
},
2617+
2618+
{
2619+
Schema: starwarsSchemaNoIntrospection,
2620+
Query: `
2621+
{
2622+
search(text: "an") {
2623+
__typename
2624+
... on Human {
2625+
name
2626+
}
2627+
... on Droid {
2628+
name
2629+
}
2630+
... on Starship {
2631+
name
2632+
}
2633+
}
2634+
}
2635+
`,
2636+
ExpectedResult: `
2637+
{
2638+
"search": [
2639+
{
2640+
"__typename": "Human",
2641+
"name": "Han Solo"
2642+
},
2643+
{
2644+
"__typename": "Human",
2645+
"name": "Leia Organa"
2646+
},
2647+
{
2648+
"__typename": "Starship",
2649+
"name": "TIE Advanced x1"
2650+
}
2651+
]
2652+
}
2653+
`,
2654+
},
26172655
})
26182656
}
26192657

internal/exec/selected/selected.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ func applySelectionSet(r *Request, s *resolvable.Schema, e *resolvable.Object, s
8181

8282
switch field.Name.Name {
8383
case "__typename":
84-
if !r.DisableIntrospection {
85-
flattenedSels = append(flattenedSels, &TypenameField{
86-
Object: *e,
87-
Alias: field.Alias.Name,
88-
})
89-
}
84+
// __typename is available even though r.DisableIntrospection == true
85+
// because it is necessary when using union types and interfaces: https://graphql.org/learn/schema/#union-types
86+
flattenedSels = append(flattenedSels, &TypenameField{
87+
Object: *e,
88+
Alias: field.Alias.Name,
89+
})
9090

9191
case "__schema":
9292
if !r.DisableIntrospection {

0 commit comments

Comments
 (0)