import DataLoader from "dataloader" ; import { User } from "../entities/User" ; export const createUserLoader = ( ) => new DataLoader < number , User > ( async ( userIds ) => { const users = await User . findByIds ( userIds as number [ ] ) ; const userIdToUser = { } ; users . forEach ( ( u ) => { userIdToUser [ u . id ] = u ; } ) ; const sortedUsers = userIds . map ( ( userId ) => userIdToUser [ userId ] ) ; return sortedUsers ; } ) ;