Skip to content

Commit

Permalink
Correct dataloader example (#3110)
Browse files Browse the repository at this point in the history
Dataloader requires the value and error slice to be of equal length, in order to correctly return the values.

Link: https://github.com/vikstrous/dataloadgen/blob/7de6ebe3d882737607ce2ba646e8d6ec652b32e3/dataloadgen_test.go#L19-L20
  • Loading branch information
mpldr committed May 28, 2024
1 parent bd9219d commit dae915d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions docs/content/reference/dataloaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ func (u *userReader) getUsers(ctx context.Context, userIDs []string) ([]*model.U
errs := make([]error, 0, len(userIDs))
for rows.Next() {
var user model.User
if err := rows.Scan(&user.ID, &user.Name); err != nil {
errs = append(errs, err)
continue
}
err := rows.Scan(&user.ID, &user.Name)
users = append(users, &user)
errs = append(errs, err)
}
return users, errs
}
Expand Down Expand Up @@ -191,4 +189,4 @@ SELECT id, todo, user_id FROM todo
SELECT id, name from user WHERE id IN (?,?,?,?,?)
```

You can see an end-to-end example [here](https://github.com/vikstrous/dataloadgen-example).
You can see an end-to-end example [here](https://github.com/vikstrous/dataloadgen-example).

0 comments on commit dae915d

Please sign in to comment.