mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Handle cases where loader returns undefined or array containing undefined
This commit is contained in:
parent
73caeb8f40
commit
5f3421ccdd
2 changed files with 3 additions and 1 deletions
|
@ -5,7 +5,7 @@ const specificResolvers = {
|
|||
Post: {
|
||||
async categories(post, args, {currentUser, Users, Categories}) {
|
||||
if (!post.categories) return [];
|
||||
const categories = await Categories.loader.loadMany(post.categories);
|
||||
const categories = _.compact(await Categories.loader.loadMany(post.categories));
|
||||
return Users.restrictViewableFields(currentUser, Categories, categories);
|
||||
},
|
||||
},
|
||||
|
|
|
@ -218,6 +218,8 @@ Users.helpers({
|
|||
*/
|
||||
Users.restrictViewableFields = function (user, collection, docOrDocs) {
|
||||
|
||||
if (!docOrDocs) return {};
|
||||
|
||||
const restrictDoc = document => _.pick(document, _.keys(Users.getViewableFields(user, collection, document)));
|
||||
|
||||
return Array.isArray(docOrDocs) ? docOrDocs.map(restrictDoc) : restrictDoc(docOrDocs);
|
||||
|
|
Loading…
Add table
Reference in a new issue