Fetching an Item by ID with a GraphQL DataLoader

Jacob Paris
InstructorJacob Paris
Share this video with your friends

Social Share Links

Send Tweet

The DataLoader class is reusable and creating a new loader is as simple as changing the batch function

Instructor: [0:00] Let's take advantage of the reusability of the DataLoader and clone our userLoader to make a postLoader. Make a PostResolver that takes an ID as an argument and calls postloader.load. Then to the schema, add post, ID string, returning a post.

[0:26] Try that new query out. Look at ID 2 here. We'll try to query that one specifically. Give ID 3 a shot, and everything is working wonderfully.