2016-11-18 16:01:27 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
|
|
|
import mutations from './mutations.js';
|
|
|
|
|
|
|
|
const resolvers = {
|
2016-11-19 20:01:17 +01:00
|
|
|
Movie: {
|
|
|
|
user(movie, args, context) {
|
|
|
|
return context.Users.findOne({ _id: movie.userId }, { fields: context.getViewableFields(context.currentUser, context.Users) });
|
|
|
|
},
|
|
|
|
},
|
2016-11-18 16:01:27 +09:00
|
|
|
Query: {
|
2016-11-19 18:01:05 +09:00
|
|
|
moviesList(root, {offset, limit}, context, info) {
|
2016-11-18 16:01:27 +09:00
|
|
|
const protectedLimit = (limit < 1 || limit > 10) ? 10 : limit;
|
|
|
|
let options = {};
|
|
|
|
options.limit = protectedLimit;
|
|
|
|
options.skip = offset;
|
|
|
|
// keep only fields that should be viewable by current user
|
|
|
|
options.fields = context.getViewableFields(context.currentUser, context.Movies);
|
|
|
|
return context.Movies.find({}, options).fetch();
|
|
|
|
},
|
2016-11-19 18:01:05 +09:00
|
|
|
moviesTotal(root, args, context) {
|
2016-11-18 16:01:27 +09:00
|
|
|
return context.Movies.find().count();
|
|
|
|
},
|
2016-11-19 18:01:05 +09:00
|
|
|
moviesSingle(root, args, context) {
|
2016-11-18 16:01:27 +09:00
|
|
|
return context.Movies.findOne({_id: args._id}, { fields: context.getViewableFields(context.currentUser, context.Movies) });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Mutation: mutations
|
|
|
|
};
|
|
|
|
|
|
|
|
// add resolvers
|
|
|
|
Telescope.graphQL.addResolvers(resolvers);
|
|
|
|
|
|
|
|
// define GraphQL queries
|
|
|
|
Telescope.graphQL.addQuery(`
|
2016-11-19 18:01:05 +09:00
|
|
|
moviesList(offset: Int, limit: Int): [Movie]
|
|
|
|
moviesTotal: Int
|
|
|
|
moviesSingle(_id: String): Movie
|
2016-11-18 16:01:27 +09:00
|
|
|
`);
|
|
|
|
|
|
|
|
export default resolvers;
|