Resolve use the appropriate sub-resolver for the given type and find the Entity matching the Id.
(rs Resolvers, id Id)
| 22 | |
| 23 | // Resolve use the appropriate sub-resolver for the given type and find the Entity matching the Id. |
| 24 | func Resolve[T Resolved](rs Resolvers, id Id) (T, error) { |
| 25 | var zero T |
| 26 | for t, resolver := range rs { |
| 27 | switch t.(type) { |
| 28 | case T: |
| 29 | val, err := resolver.(Resolver).Resolve(id) |
| 30 | if err != nil { |
| 31 | return zero, err |
| 32 | } |
| 33 | return val.(T), nil |
| 34 | } |
| 35 | } |
| 36 | return zero, fmt.Errorf("unknown type to resolve") |
| 37 | } |
| 38 | |
| 39 | var _ Resolver = &CachedResolver{} |
| 40 |