Skip to content

Validate the shape of the cacheMap at the initialization time #82

@gajus

Description

@gajus

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions