graphbrainz/src/extensions/mediawiki/loader.js
Brian Beck 898ec78a6f Add a schema extension API and several extensions (#42)
* Add a schema extension API and several extensions
* Update graphql-markdown to use new diffSchema function
* Update Node support
2017-10-19 01:00:21 -07:00

22 lines
589 B
JavaScript

import DataLoader from 'dataloader'
import LRUCache from 'lru-cache'
const debug = require('debug')('graphbrainz:extensions/mediawiki')
export default function createLoader (options) {
const { client } = options
const cache = LRUCache({
max: options.cacheSize,
maxAge: options.cacheTTL,
dispose (key) {
debug(`Removed from cache. key=${key}`)
}
})
// Make the cache Map-like.
cache.delete = cache.del
cache.clear = cache.reset
return new DataLoader(keys => {
return Promise.all(keys.map(key => client.imageInfo(key)))
}, { cacheMap: cache })
}