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

Method introValue

script/ghmock/introspection.go:110–138  ·  view source on GitHub ↗

introValue turns a resolved value into JSON, following the selection.

(v any, sel ast.SelectionSet)

Source from the content-addressed store, hash-verified

108
109// introValue turns a resolved value into JSON, following the selection.
110func (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
140type introSchema struct{}
141

Callers 2

introspectMethod · 0.95
mergeIntrospectionMethod · 0.95

Calls 5

collectMethod · 0.95
argumentsMethod · 0.95
mergeSelectionsFunction · 0.85
typeNameMethod · 0.65
resolveMethod · 0.65

Tested by

no test coverage detected