graphql/dataloader ? reverse-engineered prompt
Reverse engineered prompt
Build me a small JavaScript library for Node that helps an app fetch data more efficiently.
I want it to let me create a loader around a batch function, then call something like load(key) for individual items, while the library automatically groups requests together, sends them in one batch, and caches results so the same key is not fetched twice in the same request. It should work well for things like databases or web APIs, and be simple to use in a GraphQL style server, but also useful anywhere else.
Please include clear examples, like loading users by id, and make sure the batch function returns results in the same order as the keys. If a key has no value, it should handle that cleanly, ideally with null or an error for that item. Keep it lightweight, easy to read, and focused on Node.js with modern JavaScript promises and maps. If you need to check current docs or patterns, look them up online first.
Are you gonna build this?
make sure you review the code using coderabbit