Skip to content

Commit

Permalink
Merge pull request #687 from stereosteve/fix-includeDeprecated
Browse files Browse the repository at this point in the history
Fix: omit deprecated fields when includeDeprecated=false
  • Loading branch information
vektah authored May 1, 2019
2 parents afe33f7 + 7d0b8ee commit d1e8acd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions graphql/introspection/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (t *Type) Fields(includeDeprecated bool) []Field {
continue
}

if !includeDeprecated && f.Directives.ForName("deprecated") != nil {
continue
}

var args []InputValue
for _, arg := range f.Arguments {
args = append(args, InputValue{
Expand Down
12 changes: 11 additions & 1 deletion graphql/introspection/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func TestType(t *testing.T) {
Fields: ast.FieldList{
&ast.FieldDefinition{Name: "__schema"},
&ast.FieldDefinition{Name: "test"},
&ast.FieldDefinition{Name: "deprecated", Directives: ast.DirectiveList{
&ast.Directive{Name: "deprecated"},
}},
},
Kind: ast.Object,
},
Expand All @@ -28,9 +31,16 @@ func TestType(t *testing.T) {
require.Equal(t, "test description", schemaType.Description())
})

t.Run("fields ", func(t *testing.T) {
t.Run("fields", func(t *testing.T) {
fields := schemaType.Fields(false)
require.Len(t, fields, 1)
require.Equal(t, "test", fields[0].Name)
})

t.Run("fields includeDepricated", func(t *testing.T) {
fields := schemaType.Fields(true)
require.Len(t, fields, 2)
require.Equal(t, "test", fields[0].Name)
require.Equal(t, "deprecated", fields[1].Name)
})
}

0 comments on commit d1e8acd

Please sign in to comment.