Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new DataLoader instance.
GraphQL
const userLoader = new DataLoader([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cacheMap instead of batchLoadFn
Trying to pass maxBatchSize as the first argument
Confusing cacheKeyFn with batchLoadFn
✗ Incorrect
The batchLoadFn is the required function that DataLoader uses to batch and load keys.
2fill in blank
mediumComplete the code to load a user by ID using DataLoader.
GraphQL
userLoader.[1](userId); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using loadMany when loading a single key
Trying to call batchLoadFn directly
Using clear instead of load
✗ Incorrect
The load method loads a single key and returns a Promise for the value.
3fill in blank
hardFix the error in clearing the cache for a specific key.
GraphQL
userLoader.[1](userId); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using clearAll to clear a single key
Using prime instead of clear
Calling load instead of clearing
✗ Incorrect
The clear method removes a specific key from the cache.
4fill in blank
hardFill both blanks to add a new value to the cache and then clear it.
GraphQL
userLoader.[1](userId, userData); userLoader.[2](userId);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using load instead of prime to add cache
Using clearAll instead of clear to remove one key
Swapping the order of methods
✗ Incorrect
prime adds a key-value pair to the cache. clear removes a specific key from the cache.
5fill in blank
hardFill all three blanks to batch load multiple keys and then clear the entire cache.
GraphQL
userLoader.[1](userIds); userLoader.[2](); userLoader.[3](userId);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using load instead of loadMany for multiple keys
Using clear instead of clearAll to clear all cache
Mixing up clear and clearAll
✗ Incorrect
loadMany loads multiple keys at once. clearAll clears the entire cache. clear clears a specific key.