2016-11-03 21:39:09 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
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',
|
|
|
|
|
|
|
|
resolver(root, {offset, limit}, context, info) {
|
2016-11-03 21:39:09 +09:00
|
|
|
const options = {
|
2016-12-10 21:58:40 +09:00
|
|
|
limit: limit,
|
2016-11-22 18:14:51 -05:00
|
|
|
skip: offset,
|
|
|
|
// keep only fields that should be viewable by current user
|
|
|
|
fields: context.getViewableFields(context.currentUser, context.Categories),
|
2016-11-03 21:39:09 +09:00
|
|
|
};
|
|
|
|
return context.Categories.find({}, options).fetch();
|
|
|
|
},
|
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;
|