Skip to content

Automatically Solving the N+1 Problem with FindUnique #904

Answered by steebchen
KoichiKiyokawa asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks!

The Go client currently does not do any batching at this time. I will have to think about this. I'm wondering if this is actually a good solution as it doesn't really solve the n+1 problem universally, it just solves it for one use case (when you do multiple findUnique) – please correct me if that's wrong though.

For now, I would recommend doing .Fetch() for whatever data you most like need in the parent resolver.

For example, if you are able to fetch user -> user's posts -> post's comments, you would run into the n+1 problem.

For example:

func (r *Viewer) User(ctx context.Context, obj *models.Viewer, id string) (*db.UserModel, error) {
	return r.db.User.FindFirst(
		db.User.ID.Eq…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by KoichiKiyokawa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants