import * as DataLoader from "dataloader" ; import { getRepository } from "typeorm" ; import { User } from "../entity/User" ; export const userLoader = ( ) : DataLoader < string , User > => new DataLoader ( async ( keys ) => { const users = await getRepository ( User ) . findByIds ( keys ) ; const userMap = { } ; users . forEach ( u => { userMap [ u . id ] = u ; } ) ; return keys . map ( k => userMap [ k ] ) ; } ) ;