mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
14 lines
347 B
JavaScript
14 lines
347 B
JavaScript
|
|
import DataLoader from 'dataloader'
|
||
|
|
import MusicBrainz from './client'
|
||
|
|
|
||
|
|
const CLIENT = new MusicBrainz()
|
||
|
|
|
||
|
|
export const entityLoader = new DataLoader(keys => {
|
||
|
|
return Promise.all(keys.map(key => {
|
||
|
|
const [ entity, id, params ] = key
|
||
|
|
return CLIENT.lookup(entity, id, params)
|
||
|
|
}))
|
||
|
|
}, {
|
||
|
|
cacheKeyFn: (key) => CLIENT.getLookupURL(...key)
|
||
|
|
})
|