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

Method fill

script/ghmock/gqlscaffold.go:135–160  ·  view source on GitHub ↗

fill walks a value that's already there, adding missing fields inside it. null stays null, because that can be what the response is testing.

(path string, v any, typ *ast.Type, sel ast.SelectionSet)

Source from the content-addressed store, hash-verified

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.
135func (s *gqlScaffolder) fill(path string, v any, typ *ast.Type, sel ast.SelectionSet) any {
136 if v == nil {
137 return nil
138 }
139 if typ.Elem != nil {
140 list, ok := v.([]any)
141 if !ok {
142 return v
143 }
144 for i, item := range list {
145 list[i] = s.fill(fmt.Sprintf("%s.%d", path, i), item, typ.Elem, sel)
146 }
147 return list
148 }
149 def := s.schema.Types[typ.NamedType]
150 if def == nil {
151 return v
152 }
153 switch def.Kind {
154 case ast.Object, ast.Interface, ast.Union:
155 if obj, ok := v.(map[string]any); ok {
156 s.fillObject(path, obj, def, sel, true)
157 }
158 }
159 return v
160}
161
162// generate makes a placeholder value of a type. parent is the type of the
163// object that holds the field.

Callers 1

fillObjectMethod · 0.95

Calls 1

fillObjectMethod · 0.95

Tested by

no test coverage detected