0
0
NestJSframework~10 mins

DataLoader integration in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import DataLoader in a NestJS service.

NestJS
import [1] from 'dataloader';
Drag options to blanks, or click blank then click option'
ADataLoad
BLoaderData
CDataLoader
DLoader
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect import names like 'LoaderData' or 'DataLoad'.
Forgetting to import DataLoader before using it.
2fill in blank
medium

Complete the code to create a new DataLoader instance in a NestJS service.

NestJS
const userLoader = new DataLoader([1]);
Drag options to blanks, or click blank then click option'
AbatchLoadFn
BbatchLoaderFn
CloadBatchFn
DbatchLoadFunction
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like 'batchLoadFunction' or 'loadBatchFn'.
Passing the batch function directly without wrapping in an object.
3fill in blank
hard

Fix the error in the batch loading function signature for DataLoader.

NestJS
async function batchLoadUsers([1]) { return users; }
Drag options to blanks, or click blank then click option'
Akey
Bkeys
CuserIds
Dids
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular names like 'key' which is not an array.
Using unrelated parameter names that confuse the function purpose.
4fill in blank
hard

Fill both blanks to create a DataLoader that batches user IDs and returns users.

NestJS
const userLoader = new DataLoader(async ([1]) => {
  const users = await this.userService.findByIds([2]);
  return [1].map(id => users.find(user => user.id === id));
});
Drag options to blanks, or click blank then click option'
Akeys
BuserIds
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names between parameter and service call.
Not mapping keys to users correctly.
5fill in blank
hard

Fill all three blanks to use DataLoader in a NestJS resolver method to load a user by ID.

NestJS
async getUser(id: string) {
  const user = await this.[1].load([2]);
  return user ? [3] : null;
}
Drag options to blanks, or click blank then click option'
AuserLoader
Bid
Cuser
DuserService
Attempts:
3 left
💡 Hint
Common Mistakes
Calling load on the service instead of the DataLoader.
Returning the wrong variable or forgetting to check for null.