fillObject adds the fields that sel asks for and obj lacks. With record set, it remembers where it added them, so they can be reported.
(path string, obj map[string]any, def *ast.Definition, sel ast.SelectionSet, record bool)
| 95 | // fillObject adds the fields that sel asks for and obj lacks. With record set, |
| 96 | // it remembers where it added them, so they can be reported. |
| 97 | func (s *gqlScaffolder) fillObject(path string, obj map[string]any, def *ast.Definition, sel ast.SelectionSet, record bool) { |
| 98 | concrete := s.concreteType(def, obj, sel) |
| 99 | var keys []string |
| 100 | groups := map[string][]*ast.Field{} |
| 101 | s.collect(sel, concrete, &keys, groups) |
| 102 | |
| 103 | for _, key := range keys { |
| 104 | fields := groups[key] |
| 105 | f := fields[0] |
| 106 | child := path + "." + key |
| 107 | existing, has := obj[key] |
| 108 | switch { |
| 109 | case f.Name == "__typename": |
| 110 | if !has { |
| 111 | obj[key] = concrete.Name |
| 112 | } |
| 113 | case f.Definition == nil: |
| 114 | // The schema has no such field. The query check reports it. |
| 115 | continue |
| 116 | case strings.HasPrefix(f.Name, "__"): |
| 117 | if !has { |
| 118 | obj[key] = s.introspect(f, mergeSelections(fields)) |
| 119 | } else { |
| 120 | obj[key] = s.mergeIntrospection(child, existing, s.introspectionRoot(f), mergeSelections(fields), record) |
| 121 | } |
| 122 | case has: |
| 123 | obj[key] = s.fill(child, existing, f.Definition.Type, mergeSelections(fields)) |
| 124 | default: |
| 125 | obj[key] = s.generate(f.Definition.Type, mergeSelections(fields), f.Name, concrete.Name) |
| 126 | } |
| 127 | if !has && record { |
| 128 | s.added = append(s.added, child) |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // fill walks a value that's already there, adding missing fields inside it. |
| 134 | // null stays null, because that can be what the response is testing. |
no test coverage detected