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

Method checkScalar

script/ghmock/graphqlcheck.go:427–451  ·  view source on GitHub ↗
(path string, val any, name string)

Source from the content-addressed store, hash-verified

425}
426
427func (w *gqlWalker) checkScalar(path string, val any, name string) {
428 switch {
429 case stringScalars[name]:
430 if _, ok := val.(string); !ok {
431 w.addf(path, "should be a string (%s), but is %s", name, describeJSON(val))
432 }
433 case name == "Int":
434 n, ok := val.(json.Number)
435 if !ok {
436 w.addf(path, "should be a whole number (Int), but is %s", describeJSON(val))
437 return
438 }
439 if i, err := n.Int64(); err != nil || i < math.MinInt32 || i > math.MaxInt32 {
440 w.addf(path, "%s isn't a 32-bit whole number (Int)", n)
441 }
442 case name == "Float":
443 if _, ok := val.(json.Number); !ok {
444 w.addf(path, "should be a number (Float), but is %s", describeJSON(val))
445 }
446 case name == "Boolean":
447 if _, ok := val.(bool); !ok {
448 w.addf(path, "should be true or false (Boolean), but is %s", describeJSON(val))
449 }
450 }
451}
452
453func possibleTypeNames(schema *ast.Schema, def *ast.Definition) []string {
454 var names []string

Callers 1

checkValueMethod · 0.95

Calls 2

addfMethod · 0.95
describeJSONFunction · 0.85

Tested by

no test coverage detected