(path string, val any, typ *ast.Type, sel ast.SelectionSet, required bool)
| 376 | } |
| 377 | |
| 378 | func (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. |
no test coverage detected