mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 04:26:41 -04:00
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
import Telescope from 'meteor/nova:lib';
|
|
|
|
// add these specific resolvers separately
|
|
const specificResolvers = {
|
|
Post: {
|
|
categories(post, args, context) {
|
|
return post.categories ? context.Categories.find({_id: {$in: post.categories}}, { fields: context.getViewableFields(context.currentUser, context.Categories) }).fetch() : [];
|
|
},
|
|
},
|
|
// TODO: fix this
|
|
// Category: {
|
|
// parent(category, args, context) {
|
|
// return category.parent ? context.Categories.findOne({_id: category.parent }, { fields: context.getViewableFields(context.currentUser, context.Categories) }) : null;
|
|
// }
|
|
// },
|
|
};
|
|
Telescope.graphQL.addResolvers(specificResolvers);
|
|
|
|
// root resolvers: basic list, single, and total query resolvers
|
|
const resolvers = {
|
|
|
|
list: {
|
|
|
|
name: 'categoriesList',
|
|
|
|
resolver(root, {offset, limit}, context, info) {
|
|
const options = {
|
|
limit: limit,
|
|
skip: offset,
|
|
// keep only fields that should be viewable by current user
|
|
fields: context.getViewableFields(context.currentUser, context.Categories),
|
|
};
|
|
return context.Categories.find({}, options).fetch();
|
|
},
|
|
|
|
},
|
|
|
|
single: {
|
|
|
|
name: 'categoriesSingle',
|
|
|
|
resolver(root, {documentId}, context) {
|
|
return context.Categories.findOne({_id: documentId}, { fields: context.getViewableFields(context.currentUser, context.Categories) });
|
|
},
|
|
|
|
},
|
|
|
|
total: {
|
|
|
|
name: 'categoriesTotal',
|
|
|
|
resolver(root, args, context) {
|
|
return context.Categories.find().count();
|
|
},
|
|
|
|
}
|
|
};
|
|
|
|
export default resolvers;
|