Skip to content

Instantly share code, notes, and snippets.

@Turbiani
Created September 13, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Turbiani/6bd41a0038b43e04559dca3c4844d9f9 to your computer and use it in GitHub Desktop.
Save Turbiani/6bd41a0038b43e04559dca3c4844d9f9 to your computer and use it in GitHub Desktop.
Exemplo de Dataloader
const dependencies = {
AutenticacaoDadosRepository: require('../../infra/repository/AutenticacaoDadosRepository'),
DataLoader: require('dataloader'),
_: require('lodash'),
};
const AutenticacaoDadosLoader = (injection) => {
const {
_,
DataLoader,
AutenticacaoDadosRepository,
} = Object.assign({}, dependencies, injection);
return new DataLoader((keys) => {
return AutenticacaoDadosRepository
.buscarAutenticacaoDadosPelosIds(
{
autenticacaoDadosIds: keys,
},
injection,
).then((entities) => {
const autenticacaoDadosById = _.keyBy(entities, '_id');
return keys
.map(key => autenticacaoDadosById[key]);
});
});
};
module.exports = AutenticacaoDadosLoader;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment