diff --git a/graphql/executable_schema.go b/graphql/executable_schema.go index 7183965ed5..c2ebaa7f3f 100644 --- a/graphql/executable_schema.go +++ b/graphql/executable_schema.go @@ -32,7 +32,7 @@ func collectFields(reqCtx *OperationContext, selSet ast.SelectionSet, satisfies if !shouldIncludeNode(sel.Directives, reqCtx.Variables) { continue } - f := getOrCreateAndAppendField(&groupedFields, sel.Alias, func() CollectedField { + f := getOrCreateAndAppendField(&groupedFields, sel, func() CollectedField { return CollectedField{Field: sel} }) @@ -45,7 +45,7 @@ func collectFields(reqCtx *OperationContext, selSet ast.SelectionSet, satisfies continue } for _, childField := range collectFields(reqCtx, sel.SelectionSet, satisfies, visited) { - f := getOrCreateAndAppendField(&groupedFields, childField.Name, func() CollectedField { return childField }) + f := getOrCreateAndAppendField(&groupedFields, childField.Field, func() CollectedField { return childField }) f.Selections = append(f.Selections, childField.Selections...) } @@ -70,7 +70,7 @@ func collectFields(reqCtx *OperationContext, selSet ast.SelectionSet, satisfies } for _, childField := range collectFields(reqCtx, fragment.SelectionSet, satisfies, visited) { - f := getOrCreateAndAppendField(&groupedFields, childField.Name, func() CollectedField { return childField }) + f := getOrCreateAndAppendField(&groupedFields, childField.Field, func() CollectedField { return childField }) f.Selections = append(f.Selections, childField.Selections...) } default: @@ -96,9 +96,9 @@ func instanceOf(val string, satisfies []string) bool { return false } -func getOrCreateAndAppendField(c *[]CollectedField, name string, creator func() CollectedField) *CollectedField { +func getOrCreateAndAppendField(c *[]CollectedField, childField *ast.Field, creator func() CollectedField) *CollectedField { for i, cf := range *c { - if cf.Alias == name { + if cf.Alias == childField.Name && childField.ObjectDefinition.Name==cf.ObjectDefinition.Name { return &(*c)[i] } } @@ -109,6 +109,7 @@ func getOrCreateAndAppendField(c *[]CollectedField, name string, creator func() return &(*c)[len(*c)-1] } + func shouldIncludeNode(directives ast.DirectiveList, variables map[string]interface{}) bool { if len(directives) == 0 { return true