(ctx context.Context, dst reflect.Value, depth int, list graph.Iterator)
| 412 | } |
| 413 | |
| 414 | func (l *loader) loadIteratorToDepth(ctx context.Context, dst reflect.Value, depth int, list graph.Iterator) error { |
| 415 | if ctx == nil { |
| 416 | ctx = context.TODO() |
| 417 | } |
| 418 | if dst.Kind() == reflect.Ptr { |
| 419 | dst = dst.Elem() |
| 420 | } |
| 421 | et := dst.Type() |
| 422 | slice, chanl := false, false |
| 423 | if dst.Kind() == reflect.Slice { |
| 424 | et = et.Elem() |
| 425 | slice = true |
| 426 | } else if dst.Kind() == reflect.Chan { |
| 427 | et = et.Elem() |
| 428 | chanl = true |
| 429 | defer dst.Close() |
| 430 | } |
| 431 | fields, err := l.c.rulesFor(et) |
| 432 | if err != nil { |
| 433 | return err |
| 434 | } |
| 435 | |
| 436 | ctxDone := func() bool { |
| 437 | select { |
| 438 | case <-ctx.Done(): |
| 439 | return true |
| 440 | default: |
| 441 | } |
| 442 | return false |
| 443 | } |
| 444 | |
| 445 | if ctxDone() { |
| 446 | return ctx.Err() |
| 447 | } |
| 448 | |
| 449 | rootOnly := depth == 0 |
| 450 | it, err := l.iteratorForType(list, et, rootOnly) |
| 451 | if err != nil { |
| 452 | return err |
| 453 | } |
| 454 | defer it.Close() |
| 455 | |
| 456 | ctx = context.WithValue(ctx, fieldsCtxKey{}, fields) |
| 457 | for it.Next(ctx) { |
| 458 | if ctxDone() { |
| 459 | return ctx.Err() |
| 460 | } |
| 461 | id := l.qs.NameOf(it.Result()) |
| 462 | if id != nil { |
| 463 | if sv, ok := l.seen[id]; ok { |
| 464 | if slice { |
| 465 | dst.Set(reflect.Append(dst, sv.Elem())) |
| 466 | } else if chanl { |
| 467 | dst.Send(sv.Elem()) |
| 468 | } else if dst.Kind() != reflect.Ptr { |
| 469 | dst.Set(sv.Elem()) |
| 470 | return nil |
| 471 | } else { |
no test coverage detected