diff --git a/graphql/introspection/schema.go b/graphql/introspection/schema.go index 39e6530811..e781e5eb6d 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 { diff --git a/graphql/introspection/type.go b/graphql/introspection/type.go index 9c65b7ee81..72f993f307 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 0000000000..e3a4613c5d --- /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) + }) +}