mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00
66 lines
No EOL
1.5 KiB
JavaScript
66 lines
No EOL
1.5 KiB
JavaScript
/*
|
|
|
|
Three resolvers are defined:
|
|
|
|
- list (e.g.: moviesList(terms: JSON, offset: Int, limit: Int) )
|
|
- single (e.g.: moviesSingle(_id: String) )
|
|
- listTotal (e.g.: moviesTotal )
|
|
|
|
*/
|
|
|
|
import Telescope from 'meteor/nova:lib';
|
|
|
|
// add the "user" resolver for the Movie type separately
|
|
const movieResolver = {
|
|
Movie: {
|
|
user(movie, args, context) {
|
|
return context.Users.findOne({ _id: movie.userId }, { fields: context.getViewableFields(context.currentUser, context.Users) });
|
|
},
|
|
},
|
|
};
|
|
Telescope.graphQL.addResolvers(movieResolver);
|
|
|
|
// basic list, single, and total query resolvers
|
|
const resolvers = {
|
|
|
|
list: {
|
|
|
|
name: 'moviesList',
|
|
|
|
resolver(root, {terms, offset, limit}, context, info) {
|
|
const options = {
|
|
sort: {createdAt: -1},
|
|
// protected limit
|
|
limit: (limit < 1 || limit > 10) ? 10 : limit,
|
|
skip: offset,
|
|
// keep only fields that should be viewable by current user
|
|
fields: context.getViewableFields(context.currentUser, context.Movies),
|
|
};
|
|
return context.Movies.find({}, options).fetch();
|
|
},
|
|
|
|
},
|
|
|
|
single: {
|
|
|
|
name: 'moviesSingle',
|
|
|
|
resolver(root, {documentId}, context) {
|
|
const document = context.Movies.findOne({_id: documentId});
|
|
return _.pick(document, _.keys(context.getViewableFields(context.currentUser, context.Movies, document)));
|
|
},
|
|
|
|
},
|
|
|
|
total: {
|
|
|
|
name: 'moviesTotal',
|
|
|
|
resolver(root, {terms}, context) {
|
|
return context.Movies.find().count();
|
|
},
|
|
|
|
}
|
|
};
|
|
|
|
export default resolvers; |