From a35491e494a5053bcb120f3cd9a092b82286ede3 Mon Sep 17 00:00:00 2001 From: Yamitzky Date: Mon, 9 Apr 2018 22:06:27 +0900 Subject: [PATCH 1/2] Fix collectFields to handle aliased fields --- graphql/exec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql/exec.go b/graphql/exec.go index 37615ba7b3d..2c034888bba 100644 --- a/graphql/exec.go +++ b/graphql/exec.go @@ -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, From dfed290c02387825cad428892e69e15797bddb93 Mon Sep 17 00:00:00 2001 From: Yamitzky Date: Tue, 10 Apr 2018 00:19:34 +0900 Subject: [PATCH 2/2] Add test case for aliased field --- example/starwars/starwars_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/example/starwars/starwars_test.go b/example/starwars/starwars_test.go index 9f2912c7a33..bc33edc214d 100644 --- a/example/starwars/starwars_test.go +++ b/example/starwars/starwars_test.go @@ -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) + }) }