Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
JatinDevDG committed Aug 14, 2020
1 parent 9fcdbcd commit defd711
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions graphql/context_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,35 @@ func TestCollectAllFields(t *testing.T) {
s := CollectAllFields(ctx)
require.Equal(t, []string{"fieldA", "fieldB"}, s)
})

t.Run("collect fragments with same field name", func(t *testing.T) {
ctx := testContext(ast.SelectionSet{
&ast.InlineFragment{
TypeCondition: "ExampleTypeA",
SelectionSet: ast.SelectionSet{
&ast.Field{
Name: "fieldA",
ObjectDefinition: &ast.Definition{Name:"ExampleTypeA"},
},
},
},
&ast.InlineFragment{
TypeCondition: "ExampleTypeB",
SelectionSet: ast.SelectionSet{
&ast.Field{
Name: "fieldA",
ObjectDefinition: &ast.Definition{Name:"ExampleTypeB"},
},
},
},
})

resctx := GetFieldContext(ctx)
collected := CollectFields(GetOperationContext(ctx), resctx.Field.Selections, nil)
s := make([]string, 0, len(collected))
for _, f := range collected {
s = append(s, f.Name)
}
require.Equal(t, []string{"fieldA", "fieldA"}, s)
})
}

0 comments on commit defd711

Please sign in to comment.