collect groups the fields a selection asks for on an object of type concrete by response key, in query order. Fields that share a key are merged into one value, as GraphQL does.
(sel ast.SelectionSet, concrete *ast.Definition, keys *[]string, groups map[string][]*ast.Field)
| 312 | // concrete by response key, in query order. Fields that share a key are |
| 313 | // merged into one value, as GraphQL does. |
| 314 | func (s *gqlScaffolder) collect(sel ast.SelectionSet, concrete *ast.Definition, keys *[]string, groups map[string][]*ast.Field) { |
| 315 | for _, item := range sel { |
| 316 | switch x := item.(type) { |
| 317 | case *ast.Field: |
| 318 | if s.skipped(x.Directives) { |
| 319 | continue |
| 320 | } |
| 321 | if _, seen := groups[x.Alias]; !seen { |
| 322 | *keys = append(*keys, x.Alias) |
| 323 | } |
| 324 | groups[x.Alias] = append(groups[x.Alias], x) |
| 325 | case *ast.InlineFragment: |
| 326 | if s.skipped(x.Directives) || !s.applies(x.TypeCondition, concrete) { |
| 327 | continue |
| 328 | } |
| 329 | s.collect(x.SelectionSet, concrete, keys, groups) |
| 330 | case *ast.FragmentSpread: |
| 331 | if x.Definition == nil || s.skipped(x.Directives) || !s.applies(x.Definition.TypeCondition, concrete) { |
| 332 | continue |
| 333 | } |
| 334 | s.collect(x.Definition.SelectionSet, concrete, keys, groups) |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | func (s *gqlScaffolder) applies(cond string, concrete *ast.Definition) bool { |
| 340 | return cond == "" || concrete == nil || isA(s.schema, concrete, cond) |
no test coverage detected