2016-12-12 10:41:50 +09:00
|
|
|
import { GraphQLSchema } from 'meteor/nova:core';
|
2016-11-03 21:39:09 +09:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
// add these specific resolvers separately
|
|
|
|
const specificResolvers = {
|
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
|
|
|
},
|
|
|
|
},
|
2016-12-08 23:48:16 +01:00
|
|
|
// 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;
|
|
|
|
// }
|
|
|
|
// },
|
2016-11-22 18:14:51 -05:00
|
|
|
};
|
2016-12-12 10:41:50 +09:00
|
|
|
GraphQLSchema.addResolvers(specificResolvers);
|
2016-11-22 18:14:51 -05:00
|
|
|
|
|
|
|
// root resolvers: basic list, single, and total query resolvers
|
|
|
|
const resolvers = {
|
|
|
|
|
|
|
|
list: {
|
|
|
|
|
|
|
|
name: 'categoriesList',
|
|
|
|
|
2017-01-07 16:44:50 +09:00
|
|
|
resolver(root, {terms}, context, info) {
|
2017-01-05 15:53:41 +01:00
|
|
|
let {selector, options} = context.Categories.getParameters(terms);
|
|
|
|
|
2017-01-08 16:25:30 +09:00
|
|
|
options.limit = terms.limit;
|
|
|
|
options.skip = terms.offset;
|
2017-01-05 15:53:41 +01:00
|
|
|
options.fields = context.getViewableFields(context.currentUser, context.Categories);
|
|
|
|
|
|
|
|
return context.Categories.find(selector, options).fetch();
|
2016-11-03 21:39:09 +09:00
|
|
|
},
|
2016-11-22 18:14:51 -05:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
single: {
|
2016-12-08 23:48:16 +01:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
name: 'categoriesSingle',
|
2016-12-08 23:48:16 +01:00
|
|
|
|
2016-11-30 16:54:58 +09:00
|
|
|
resolver(root, {documentId}, context) {
|
|
|
|
return context.Categories.findOne({_id: documentId}, { fields: context.getViewableFields(context.currentUser, context.Categories) });
|
2016-11-03 21:39:09 +09:00
|
|
|
},
|
2016-12-08 23:48:16 +01:00
|
|
|
|
2016-11-03 21:39:09 +09:00
|
|
|
},
|
2016-11-22 18:14:51 -05:00
|
|
|
|
|
|
|
total: {
|
2016-12-08 23:48:16 +01:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
name: 'categoriesTotal',
|
2016-12-08 23:48:16 +01:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
resolver(root, args, context) {
|
|
|
|
return context.Categories.find().count();
|
|
|
|
},
|
2016-12-08 23:48:16 +01:00
|
|
|
|
2016-11-22 18:14:51 -05:00
|
|
|
}
|
2016-11-03 21:39:09 +09:00
|
|
|
};
|
|
|
|
|
2016-12-08 23:48:16 +01:00
|
|
|
export default resolvers;
|