Skip to content

Commit 84ce153

Browse files
authored
fixed bug preventing client for asking for __typename (#73)
1 parent 53bdf20 commit 84ce153

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

gateway.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,15 @@ func fieldURLs(schemas []*graphql.RemoteSchema, stripInternal bool) FieldURLMap
251251
for _, remoteSchema := range schemas {
252252
// each type defined by the schema can be found at remoteSchema.URL
253253
for name, typeDef := range remoteSchema.Schema.Types {
254+
255+
// if the type is part of the introspection (and can't be left up to the backing services)
254256
if !strings.HasPrefix(typeDef.Name, "__") || !stripInternal {
257+
// you can ask for __typename at any service that defines the type
258+
locations.RegisterURL(name, "__typename", remoteSchema.URL)
259+
255260
// each field of each type can be found here
256261
for _, fieldDef := range typeDef.Fields {
262+
257263
// if the field is not an introspection field
258264
if !(name == "Query" && strings.HasPrefix(fieldDef.Name, "__")) {
259265
locations.RegisterURL(name, fieldDef.Name, remoteSchema.URL)

gateway_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,16 @@ func TestGateway(t *testing.T) {
313313
}, res)
314314
})
315315

316+
t.Run("Introspection field on services", func(t *testing.T) {
317+
// compute the location of each field
318+
locations := fieldURLs(sources, false)
319+
320+
// make sure we have entries for __typename at each service
321+
userTypenameURLs, err := locations.URLFor("User", "__typename")
322+
assert.Nil(t, err)
323+
assert.Equal(t, []string{"url1", "url2"}, userTypenameURLs)
324+
})
325+
316326
t.Run("Gateway fields", func(t *testing.T) {
317327
// define a gateway field
318328
viewerField := &QueryField{

0 commit comments

Comments
 (0)