First returns the first Entity entity from the query. Returns a *NotFoundError when no Entity was found.
(ctx context.Context)
| 133 | // First returns the first Entity entity from the query. |
| 134 | // Returns a *NotFoundError when no Entity was found. |
| 135 | func (eq *EntityQuery) First(ctx context.Context) (*Entity, error) { |
| 136 | nodes, err := eq.Limit(1).All(setContextOp(ctx, eq.ctx, "First")) |
| 137 | if err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | if len(nodes) == 0 { |
| 141 | return nil, &NotFoundError{entity.Label} |
| 142 | } |
| 143 | return nodes[0], nil |
| 144 | } |
| 145 | |
| 146 | // FirstX is like First, but panics if an error occurs. |
| 147 | func (eq *EntityQuery) FirstX(ctx context.Context) *Entity { |
no test coverage detected