Filter undefined results

This commit is contained in:
Aurelsicoko 2018-11-22 17:33:51 +01:00
parent 0074ca6304
commit f833622e19
2 changed files with 7 additions and 5 deletions

View File

@ -21,7 +21,9 @@ module.exports = {
// Run queries in parallel.
const results = await Promise.all(queries.map((query) => this.makeQuery(model, query)));
// Use to match initial queries order.
resolve(this.mapData(model, keys, map, results));
const data = this.mapData(model, keys, map, results);
resolve(data);
} catch (e) {
reject(e);
}
@ -45,9 +47,9 @@ module.exports = {
// Extracting ids from original request to map with query results.
const ids = query.options.query[ref.primaryKey];
return ids.map(id =>
data.find(entry => (entry._id || entry.id || '').toString() === id.toString())
);
return ids
.map(id => data.find(entry => (entry._id || entry.id || '').toString() === id.toString()))
.filter(entry => entry !== undefined);
});
},

View File

@ -439,7 +439,7 @@ module.exports = {
}
return association.model ?
resolvers.fetch(params, association.plugin, []):
Loaders.loaders[association.collection || association.model].load({ params, options: queryOpts, single: true }):
Loaders.loaders[association.collection || association.model].load({ options: queryOpts });
// const value = await (association.model