-
Notifications
You must be signed in to change notification settings - Fork 520
Closed
Description
The current implementation assumes that the cacheMap
object has the required shape without making checks. This results in the DataLoader
failing in hard to replace scenarios.
In the specific case I was debugging, I've started getting an error:
TypeError: this._promiseCache.delete is not a function
at DataLoader.clear (/Users/gajus/Documents/dev/applaudience/showtime-api/node_modules/dataloader/index.js:126:30)
at /Users/gajus/Documents/dev/applaudience/showtime-api/node_modules/dataloader/index.js:292:12
at Array.forEach (native)
at failedDispatch (/Users/gajus/Documents/dev/applaudience/showtime-api/node_modules/dataloader/index.js:288:9)
at /Users/gajus/Documents/dev/applaudience/showtime-api/node_modules/dataloader/index.js:281:12
This error appeared because I am using lru-cache
instead of Map to implement the cache. Turns out that lru-cache
API is not compatible with Map
and therefore does not work with DataLoader
without a wrapper. The problem is that I've only learned this in an error scenario when DataLoader
had to use delete
strategy.
The solution: validate the shape of the cacheMap
input at the time of constructing an instance of DataLoader
to assert that it has all the required methods required to work with DataLoader
.
Metadata
Metadata
Assignees
Labels
No labels