Hi, guys!
I like a lot the new direction that Graphcool is taken!
I think, we should add a "Best Practices" section in the documentation, explaining how to use DataLoader to avoid multiple requests to the database service.
IMO, I think this is worth because DataLoader will increase the performance of the app and it will decrease the costs of having multiple calls to the database service.
I am looking forward to hear more about this and discuss it deeper.
Wouldn't it be possible for graphcool-binding to do something similar to what Appollo-Client does? So essentially automatically batching calls that fall into the same tick.
I haven't yet really used DataLoader since I got kinda scared of the boilerplate code it requires, so I might be missing some other advantages of DataLoader...
I am working on a caching implementation for the entire server (similar to what Apollo Engine does with caching). This is a better solution to this problem, because DataLoader will always be linked to a single binding.
And because the GraphQL server is _not_ the client, there are issues with user specific data. That works fine for a client implementation, but not for a server implementation that multiple clients will connect to simultaneously.
For batching, there is already an open issue here: https://github.com/graphcool/graphcool-binding/issues/7
:wave: I'm interested in learning how DataLoader works!
Thanks a lot for opening this issue @jferrettiboke! As the data loader is baked into Prisma bindings and that's the recommended way to use Prisma, I think we don't need any other explicit documentation on this. In any case, I also added a note about this to our new docs which you can find here.
Also note that this article has quite a bit of information about the data loader.
@nikolasburk, how do I put the dataloader to use if I want to cache my queries? I know how to use it by itself, but I do not understand how it is integrated into Prisma. Is there any global switch to turn on or off caching, or do I have to implement it myself?
Would be great to get some input on how to implement dataloader with prisma and apollo-server.
@nikolasburk You said that it is baked into prisma, but in how far? Basically I want to have a per request dataloader cache to avoid duplicate calls to the database when fetching a list of nested fields for example. Should I implement it myself or is there something like that already built into prisma?
Edit: After thinking a bit more about it, I guess the prisma service itself is using dataloader internally but I need to implement dataloader for my own graphql server in order to batch and cache multiple prisma requests in one request. Is that correct?
Most helpful comment
I am working on a caching implementation for the entire server (similar to what Apollo Engine does with caching). This is a better solution to this problem, because DataLoader will always be linked to a single binding.
And because the GraphQL server is _not_ the client, there are issues with user specific data. That works fine for a client implementation, but not for a server implementation that multiple clients will connect to simultaneously.
For batching, there is already an open issue here: https://github.com/graphcool/graphcool-binding/issues/7