Skip to content

Batching #365

Apr 18, 2020 · 10 comments · 31 replies
Discussion options

You must be logged in to vote

I was able to write a batching mechanism by combining react-query with dataloader, and it works remarkably well. I built a little demonstration CodeSandbox: https://codesandbox.io/s/react-query-dataloader-lgosp

Key points:

  • Both react-query and dataloader have caches so we need to disable dataloader's cache and let react-query manage it all. That way we get de-duplication and caching from react-query, and batching from dataloader.
  • You want to keep a single loader rather than multiple in order to batch correctly
  • dataloader requires the fetch function to return data in the same order as requested, so make sure your fetch function sorts the data before returning it.
  • You can just as easy load…

Replies: 10 comments 31 replies

Comment options

You must be logged in to vote
1 reply
@KATT
Comment options

Comment options

You must be logged in to vote
7 replies
@kamranayub
Comment options

@TkDodo
Comment options

@kamranayub
Comment options

@kamranayub
Comment options

@KATT
Comment options

Comment options

You must be logged in to vote
3 replies
@kamranayub
Comment options

@cromosom
Comment options

@kamranayub
Comment options

Comment options

You must be logged in to vote
3 replies
@TkDodo
Comment options

@sseppola
Comment options

@kamilkisiela
Comment options

Answer selected by TkDodo
Comment options

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

@Shenlok
Comment options

Comment options

You must be logged in to vote
1 reply
@TkDodo
Comment options

Comment options

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

@IronTony
Comment options

Comment options

You must be logged in to vote
12 replies
@yornaath
Comment options

@Play-AV
Comment options

@yornaath
Comment options

@Play-AV
Comment options

@tho-graf
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment