Skip to content

Commit

Permalink
Merge pull request 99designs#246 from vektah/fix-introspection
Browse files Browse the repository at this point in the history
Fix introspection
  • Loading branch information
vektah authored Aug 2, 2018
2 parents b165407 + 40dc728 commit a6daa3f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions graphql/introspection/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions graphql/introspection/type.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package introspection

import (
"strings"

"github.com/vektah/gqlparser/ast"
)

Expand Down Expand Up @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions graphql/introspection/type_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}

0 comments on commit a6daa3f

Please sign in to comment.