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

Method checkValue

script/ghmock/graphqlcheck.go:378–416  ·  view source on GitHub ↗
(path string, val any, typ *ast.Type, sel ast.SelectionSet, required bool)

Source from the content-addressed store, hash-verified

376}
377
378func (w *gqlWalker) checkValue(path string, val any, typ *ast.Type, sel ast.SelectionSet, required bool) {
379 if val == nil {
380 if typ.NonNull {
381 w.addf(path, "is null, but GitHub's schema says it can't be (%s)", typ.String())
382 }
383 return
384 }
385 if typ.Elem != nil {
386 list, ok := val.([]any)
387 if !ok {
388 w.addf(path, "should be a list (%s), but is %s", typ.String(), describeJSON(val))
389 return
390 }
391 for i, item := range list {
392 w.checkValue(fmt.Sprintf("%s.%d", path, i), item, typ.Elem, sel, required)
393 }
394 return
395 }
396
397 def := w.schema.Types[typ.NamedType]
398 if def == nil {
399 return
400 }
401 switch def.Kind {
402 case ast.Scalar:
403 w.checkScalar(path, val, def.Name)
404 case ast.Enum:
405 if s, ok := val.(string); !ok || def.EnumValues.ForName(s) == nil {
406 w.addf(path, "%s isn't a value of %s; it can be %s", jsonText(val), def.Name, listNames(enumValueNames(def), 10))
407 }
408 case ast.Object, ast.Interface, ast.Union:
409 obj, ok := val.(map[string]any)
410 if !ok {
411 w.addf(path, "should be an object (%s), but is %s", def.Name, describeJSON(val))
412 return
413 }
414 w.checkObject(path, obj, def, sel, required)
415 }
416}
417
418// stringScalars are the scalars GitHub always sends as JSON strings. Others,
419// such as CustomPropertyValue, can hold more than one JSON type.

Callers 1

checkObjectMethod · 0.95

Calls 8

addfMethod · 0.95
checkScalarMethod · 0.95
checkObjectMethod · 0.95
describeJSONFunction · 0.85
jsonTextFunction · 0.85
listNamesFunction · 0.85
enumValueNamesFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected