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)
| 162 | // generate makes a placeholder value of a type. parent is the type of the |
| 163 | // object that holds the field. |
| 164 | func (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. |
no test coverage detected