import DataLoader from "dataloader" ; import hash from "object-hash" ; import { Entity , EntityConstructor , EntityManager , isEntity } from "../EntityManager" ; import { FilterAndSettings } from "../QueryBuilder" ; import { getOrSet } from "../utils" ; export function findDataLoader < T extends Entity > ( em , type ) { return getOrSet ( em . findLoaders , type . name , ( ) => { return new DataLoader < FilterAndSettings < T > , unknown [ ] , string > ( ( queries ) => { return em . driver . find ( em , type , queries ) ; } , { cacheKeyFn : whereFilterHash , } ) ; } ) ; } const replacer = ( v ) => ( isEntity ( v ) ? v . id : v ) ; export function whereFilterHash ( where ) { return hash ( where , { replacer } ) ; }