Skip to content

Commit

Permalink
Merge pull request #84 from yamitzky/master
Browse files Browse the repository at this point in the history
Fix collectFields to handle aliased fields properly
  • Loading branch information
vektah authored Apr 9, 2018
2 parents 4d2eece + ba2ecb1 commit 546b7b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions example/starwars/starwars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,20 @@ func TestStarwars(t *testing.T) {
var resp interface{}
c.MustPost(introspection.Query, &resp)
})

t.Run("aliased field and non-aliased field", func(t *testing.T) {
var resp struct {
Character struct {
Name string
}
AliasedCharacter struct {
Name string
}
}
c.MustPost(`{
character(id: 2001) { name }
aliasedCharacter: character(id: 2001) { name }
}`, &resp)
require.Equal(t, resp.Character, resp.AliasedCharacter)
})
}
2 changes: 1 addition & 1 deletion graphql/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func collectFields(doc *query.Document, selSet []query.Selection, satisfies []st
for _, sel := range selSet {
switch sel := sel.(type) {
case *query.Field:
f := getOrCreateField(&groupedFields, sel.Name.Name, func() CollectedField {
f := getOrCreateField(&groupedFields, sel.Alias.Name, func() CollectedField {
f := CollectedField{
Alias: sel.Alias.Name,
Name: sel.Name.Name,
Expand Down

0 comments on commit 546b7b7

Please sign in to comment.