MCPcopy Create free account
hub / github.com/cli/cli / collect

Method collect

script/ghmock/gqlscaffold.go:314–337  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

312// concrete by response key, in query order. Fields that share a key are
313// merged into one value, as GraphQL does.
314func (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
339func (s *gqlScaffolder) applies(cond string, concrete *ast.Definition) bool {
340 return cond == "" || concrete == nil || isA(s.schema, concrete, cond)

Callers 4

fillObjectMethod · 0.95
concreteTypeMethod · 0.95
mergeIntrospectionMethod · 0.95
introValueMethod · 0.95

Calls 2

skippedMethod · 0.95
appliesMethod · 0.95

Tested by

no test coverage detected