mirror of
https://github.com/wassname/talk.git
synced 2026-06-29 19:17:51 +08:00
24 lines
562 B
JavaScript
24 lines
562 B
JavaScript
const SettingsService = require('../../services/settings');
|
|
const DataLoader = require('dataloader');
|
|
|
|
/**
|
|
* Creates a set of loaders based on a GraphQL context.
|
|
* @param {Object} context the context of the GraphQL request
|
|
* @return {Object} object of loaders
|
|
*/
|
|
module.exports = () => {
|
|
const loader = new DataLoader(selections =>
|
|
Promise.all(
|
|
selections.map(fields => {
|
|
return SettingsService.retrieve(fields);
|
|
})
|
|
)
|
|
);
|
|
|
|
return {
|
|
Settings: {
|
|
load: (fields = false) => loader.load(fields),
|
|
},
|
|
};
|
|
};
|