2018-01-25 15:03:03 -06:00
|
|
|
import { addCallback, addGraphQLSchema, addGraphQLResolvers, addGraphQLMutation } from 'meteor/vulcan:core';
|
2017-09-28 18:15:04 +09:00
|
|
|
import { performVoteServer } from '../modules/vote.js';
|
2017-09-04 20:56:03 +09:00
|
|
|
import { VoteableCollections } from '../modules/make_voteable.js';
|
|
|
|
|
|
|
|
function CreateVoteableUnionType() {
|
2017-09-25 22:09:09 +02:00
|
|
|
const voteableSchema = VoteableCollections.length ? `union Voteable = ${VoteableCollections.map(collection => collection.typeName).join(' | ')}` : '';
|
|
|
|
addGraphQLSchema(voteableSchema);
|
2017-09-04 20:56:03 +09:00
|
|
|
return {}
|
|
|
|
}
|
|
|
|
addCallback('graphql.init.before', CreateVoteableUnionType);
|
2016-11-22 18:39:50 -05:00
|
|
|
|
2017-01-29 11:17:00 +09:00
|
|
|
const resolverMap = {
|
2017-09-04 20:56:03 +09:00
|
|
|
Voteable: {
|
2017-01-29 11:17:00 +09:00
|
|
|
__resolveType(obj, context, info){
|
2017-09-04 20:56:03 +09:00
|
|
|
return obj.__typename;
|
2017-01-29 11:17:00 +09:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2017-01-09 15:42:24 +09:00
|
|
|
|
2017-07-13 17:37:59 +09:00
|
|
|
addGraphQLResolvers(resolverMap);
|
2017-01-09 15:42:24 +09:00
|
|
|
|
2017-09-28 18:15:04 +09:00
|
|
|
addGraphQLMutation('vote(documentId: String, voteType: String, collectionName: String, voteId: String) : Voteable');
|
2016-11-22 18:39:50 -05:00
|
|
|
|
|
|
|
const voteResolver = {
|
|
|
|
Mutation: {
|
2017-09-28 18:15:04 +09:00
|
|
|
async vote(root, {documentId, voteType, collectionName, voteId}, context) {
|
2017-09-04 20:56:03 +09:00
|
|
|
|
2017-09-25 22:09:09 +02:00
|
|
|
const { currentUser } = context;
|
2017-09-27 17:15:49 +02:00
|
|
|
const collection = context[collectionName];
|
2017-09-25 22:09:09 +02:00
|
|
|
|
2018-02-11 13:18:06 +09:00
|
|
|
const document = await performVoteServer({documentId, voteType, collection, voteId, user: currentUser});
|
2017-09-28 18:15:04 +09:00
|
|
|
return document;
|
2017-09-25 22:09:09 +02:00
|
|
|
|
2016-11-22 18:39:50 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-07-13 17:37:59 +09:00
|
|
|
addGraphQLResolvers(voteResolver);
|