Install the DataLoader Package

Jacob Paris
InstructorJacob Paris
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

The GraphQL Foundation has an official DataLoader package that is well-maintained and more feature complete than what we've built so far.

Instructor: [0:00] We've now built a functional DataLoader step by step showing exactly why each step is needed. This API is very close to the official DataLoader package maintained by the GraphQL Foundation, or we can install with npm install --save DataLoader. Import the DataLoader package, const DataLoader = require('dataloader').

[0:25] Then we can delete the big class we've been writing. The API matches up perfectly, so we'll already be using this DataLoader package for our userLoader. If you hover over, you can see the type signature is being pulled from the package, which we did not write ourselves. That's going to be SELECT ALL FROM users WHERE ID IN (IDs).

[0:51] We have one request for posts and one request for all of the users at once.