Skip to content

Commit

Permalink
Ignore __ fields in instrospection
Browse files Browse the repository at this point in the history
  • Loading branch information
creativej committed Aug 2, 2018
1 parent b38c580 commit 62d4c8a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
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 62d4c8a

Please sign in to comment.