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

Method generate

script/ghmock/gqlscaffold.go:164–195  ·  view source on GitHub ↗

generate makes a placeholder value of a type. parent is the type of the object that holds the field.

(typ *ast.Type, sel ast.SelectionSet, field, parent string)

Source from the content-addressed store, hash-verified

162// generate makes a placeholder value of a type. parent is the type of the
163// object that holds the field.
164func (s *gqlScaffolder) generate(typ *ast.Type, sel ast.SelectionSet, field, parent string) any {
165 if typ.Elem != nil {
166 s.placeholders = true
167 return []any{s.generate(typ.Elem, sel, field, parent)}
168 }
169 def := s.schema.Types[typ.NamedType]
170 if def == nil {
171 return nil
172 }
173 switch def.Kind {
174 case ast.Scalar:
175 s.placeholders = true
176 return s.scalar(def.Name, field, parent)
177 case ast.Enum:
178 s.placeholders = true
179 var values []string
180 for _, v := range def.EnumValues {
181 if !deprecated(v.Directives) {
182 values = append(values, v.Name)
183 }
184 }
185 if len(values) == 0 {
186 values = enumValueNames(def)
187 }
188 return enumPlaceholder(values)
189 case ast.Object, ast.Interface, ast.Union:
190 obj := map[string]any{}
191 s.fillObject("", obj, def, sel, false)
192 return obj
193 }
194 return nil
195}
196
197// scalar makes a placeholder for a scalar field. Strings hold the field's
198// name, so gh's output shows where each value came from.

Callers 1

fillObjectMethod · 0.95

Calls 5

scalarMethod · 0.95
fillObjectMethod · 0.95
deprecatedFunction · 0.85
enumValueNamesFunction · 0.85
enumPlaceholderFunction · 0.85

Tested by

no test coverage detected