Exercise: Implementing DataLoader
Explore how to implement a DataLoader to batch and cache database requests in a GraphQL server. This lesson guides you through creating a usersLoader, integrating it into resolvers, and observing performance improvements by significantly reducing query counts.
In this exercise, we’ll implement a DataLoader to load objects from the users collection. Similar to how we did it in the previous lesson, we’ll have to add a new function to create a new DataLoader. Then, we’ll have to update our resolvers to use the new DataLoader instead of querying a database directly.
Exercise source code
To get the source code for this exercise, run the following command in the project’s repository:
git checkout data-loader-exercise
Practice demo
{
"ext": "js,graphql",
"delay": 2000
}Practice demo
How to start a project
Before we start writing code, here’s a quick reminder on how to run the ...