introValue turns a resolved value into JSON, following the selection.
(v any, sel ast.SelectionSet)
| 108 | |
| 109 | // introValue turns a resolved value into JSON, following the selection. |
| 110 | func (s *gqlScaffolder) introValue(v any, sel ast.SelectionSet) any { |
| 111 | switch v := v.(type) { |
| 112 | case introObject: |
| 113 | var keys []string |
| 114 | groups := map[string][]*ast.Field{} |
| 115 | s.collect(sel, s.schema.Types[v.typeName()], &keys, groups) |
| 116 | obj := map[string]any{} |
| 117 | for _, key := range keys { |
| 118 | f := groups[key][0] |
| 119 | if f.Name == "__typename" { |
| 120 | obj[key] = v.typeName() |
| 121 | continue |
| 122 | } |
| 123 | obj[key] = s.introValue(v.resolve(s, f.Name, s.arguments(f)), mergeSelections(groups[key])) |
| 124 | } |
| 125 | return obj |
| 126 | case []introObject: |
| 127 | if v == nil { |
| 128 | return nil |
| 129 | } |
| 130 | list := make([]any, len(v)) |
| 131 | for i, item := range v { |
| 132 | list[i] = s.introValue(item, sel) |
| 133 | } |
| 134 | return list |
| 135 | default: |
| 136 | return v |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | type introSchema struct{} |
| 141 |
no test coverage detected