Skip to content

Request batching - single db query #921

Answered by KATT
mmkal asked this question in Q&A
Sep 10, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hey!

Yeah, your backend needs to have a dataloader or similar.

If you use Prisma, you get this behaviour out-of-the-box as their .findUnique()-etc waits a tick before being called. How that works you can see in their video here: https://www.youtube.com/watch?v=7oMfBGEdwsc

For a reference example, you can pull down the next-prisma-starter and comment out these lines

// useEffect(() => {
// postsQuery.data?.forEach((post) => {
// utils.prefetchQuery(['post.byId', post.id]);
// });
// }, [postsQuery.data, utils]);

The above will prefetch all the data from the post.byId-proced…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mmkal
Comment options

mmkal Sep 10, 2021
Collaborator Author

@KATT
Comment options

Answer selected by mmkal
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