2016-11-03 21:39:09 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-11-08 10:29:05 +01:00
|
|
|
import mutations from './mutations.js';
|
2016-11-03 21:39:09 +09:00
|
|
|
|
2016-11-08 15:04:17 +09:00
|
|
|
export default resolvers = {
|
2016-11-03 21:39:09 +09:00
|
|
|
Post: {
|
|
|
|
categories(post, args, context) {
|
2016-11-04 09:31:32 +09:00
|
|
|
return post.categories ? context.Categories.find({_id: {$in: post.categories}}, { fields: context.getViewableFields(context.currentUser, context.Categories) }).fetch() : [];
|
2016-11-03 21:39:09 +09:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Category: {
|
|
|
|
parent(category, args, context) {
|
2016-11-04 09:31:32 +09:00
|
|
|
return category.parent ? context.Categories.findOne({_id: category.parent }, { fields: context.getViewableFields(context.currentUser, context.Categories) }) : null;
|
2016-11-03 21:39:09 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Query: {
|
|
|
|
categories(root, args, context) {
|
|
|
|
const options = {
|
2016-11-04 09:31:32 +09:00
|
|
|
fields: context.getViewableFields(context.currentUser, context.Categories)
|
2016-11-03 21:39:09 +09:00
|
|
|
};
|
|
|
|
return context.Categories.find({}, options).fetch();
|
|
|
|
},
|
2016-11-13 13:43:36 +01:00
|
|
|
categoriesListTotal(root, args, context) {
|
|
|
|
return context.Categories.find({}).count();
|
|
|
|
},
|
2016-11-03 21:39:09 +09:00
|
|
|
category(root, args, context) {
|
2016-11-04 09:31:32 +09:00
|
|
|
return context.Categories.findOne({_id: args._id}, { fields: context.getViewableFields(context.currentUser, context.Categories) });
|
2016-11-03 21:39:09 +09:00
|
|
|
},
|
|
|
|
},
|
2016-11-08 10:29:05 +01:00
|
|
|
Mutation: mutations,
|
2016-11-03 21:39:09 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
Telescope.graphQL.addResolvers(resolvers);
|