From 28b71f15b63d695fbf9662ab83c8d5b9f018b153 Mon Sep 17 00:00:00 2001 From: creativej Date: Thu, 2 Aug 2018 13:32:19 +1000 Subject: [PATCH 1/2] Return the correct mutation & subscription type --- graphql/introspection/schema.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphql/introspection/schema.go b/graphql/introspection/schema.go index 39e6530811f..e781e5eb6d0 100644 --- a/graphql/introspection/schema.go +++ b/graphql/introspection/schema.go @@ -19,11 +19,11 @@ func (s *Schema) QueryType() *Type { } func (s *Schema) MutationType() *Type { - return WrapTypeFromDef(s.schema, s.schema.Query) + return WrapTypeFromDef(s.schema, s.schema.Mutation) } func (s *Schema) SubscriptionType() *Type { - return WrapTypeFromDef(s.schema, s.schema.Query) + return WrapTypeFromDef(s.schema, s.schema.Subscription) } func (s *Schema) Directives() []Directive { From 40dc728d228c83bfe75e66c2e4562d6a6352b231 Mon Sep 17 00:00:00 2001 From: creativej Date: Thu, 2 Aug 2018 13:33:36 +1000 Subject: [PATCH 2/2] Ignore __ fields in instrospection --- graphql/introspection/type.go | 6 +++++ graphql/introspection/type_test.go | 36 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 graphql/introspection/type_test.go diff --git a/graphql/introspection/type.go b/graphql/introspection/type.go index 9c65b7ee813..72f993f3079 100644 --- a/graphql/introspection/type.go +++ b/graphql/introspection/type.go @@ -1,6 +1,8 @@ package introspection import ( + "strings" + "github.com/vektah/gqlparser/ast" ) @@ -63,6 +65,10 @@ func (t *Type) Fields(includeDeprecated bool) []Field { } var fields []Field for _, f := range t.def.Fields { + if strings.HasPrefix(f.Name, "__") { + continue + } + fields = append(fields, Field{ Name: f.Name, Description: f.Description, diff --git a/graphql/introspection/type_test.go b/graphql/introspection/type_test.go new file mode 100644 index 00000000000..e3a4613c5dd --- /dev/null +++ b/graphql/introspection/type_test.go @@ -0,0 +1,36 @@ +package introspection + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/vektah/gqlparser/ast" +) + +func TestType(t *testing.T) { + schemaType := Type{ + def: &ast.Definition{ + Name: "Query", + Description: "test description", + Fields: ast.FieldList{ + &ast.FieldDefinition{Name: "__schema"}, + &ast.FieldDefinition{Name: "test"}, + }, + Kind: ast.Object, + }, + } + + t.Run("name", func(t *testing.T) { + require.Equal(t, "Query", schemaType.Name()) + }) + + t.Run("description", func(t *testing.T) { + require.Equal(t, "test description", schemaType.Description()) + }) + + t.Run("fields ", func(t *testing.T) { + fields := schemaType.Fields(false) + require.Len(t, fields, 1) + require.Equal(t, "test", fields[0].Name) + }) +}