Skip to content

Commit

Permalink
added check for object defination name
Browse files Browse the repository at this point in the history
  • Loading branch information
JatinDevDG committed Aug 14, 2020
1 parent 08eee0f commit 849e3ea
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions graphql/executable_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
})

Expand All @@ -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...)
}

Expand All @@ -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:
Expand All @@ -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]
}
}
Expand All @@ -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
Expand Down

0 comments on commit 849e3ea

Please sign in to comment.