Skip to content

Instantly share code, notes, and snippets.

View voby's full-sized avatar

Oleksandr Vorobyov voby

View GitHub Profile
import DataLoader from 'dataloader';
function indexResults(results, indexField, cacheKeyFn = key => key) {
const indexedResults = new Map();
results.forEach((res) => {
indexedResults.set(cacheKeyFn(res[indexField]), res);
});
return indexedResults;
}