-
Notifications
You must be signed in to change notification settings - Fork 2
/
schemaResolver.js
66 lines (64 loc) · 2.51 KB
/
schemaResolver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var graph = require('graphql');
var Db = require('./db.js');
//define our custom DateTime type
const myDateType = new graph.GraphQLScalarType({
name: 'DateTime',
description: 'Description of DateTime scalar type',
serialize(value) {
return value.getTime();
},
parseValue(value) {
return new Date(value);
},
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return parseInt(ast.value, 10);
}
}
});
const resolvers = {
DateTime: {
myDateType
},
Query: {
admin_settings: (root, args)=> Db.models.admin_settings.findAll({where: args}),
authorities: (root, args)=> Db.models.authorities.findAll({where: args}),
budget_vote: (root, args)=> Db.models.budget_vote.findAll({where:{issue_num: args.issue_num}}),
budget_votes: (root, args)=> Db.models.budget_vote.findAll({where: args}),
dataface_failed_logins: (root, args)=> Db.models.dataface_failed_logins.findAll({where: args}),
dataface_modules: (root, args)=> Db.models.dataface_modules.findAll({where: args}),
dataface_mtimes: (root, args)=> Db.models.dataface_mtimes.findAll({where: args}),
dataface_version: (root, args)=> Db.models.dataface_version.findAll({where: args}),
github_users: (root, args)=> Db.models.github_users.findAll({where: args}),
github_user: (root, args)=> Db.models.github_user.findAll({where: {login: args.login}}),
issues: (root, args)=> Db.models.issue.findAll({where: args}),
issue: (root, args)=> Db.models.issue.findAll({where: {num: args.num}}),
pay_period: (root, args)=> Db.models.pay_period.findAll({where: args}),
reward_vote: (root, args)=> Db.models.reward_vote.findAll({where: args}),
trust_cert: (root, args)=> Db.models.trust_cert.findAll({where: args})
},
Mutation: {
createIssue: async (_, {num, title, labels, createdAt, updatedAt, state, repo}) =>{
let isCreated=false;
await Db.models.issue.create({
num: num,
title: title,
labels: labels,
createdAt: createdAt,
updatedAt: updatedAt,
state: state,
repo: repo
}).then(() => {
isCreated = true;
}).catch((err) => {
isCreated = false;
});
if (isCreated == true){
return "Issue created successfully";
} else {
return "Issue was not created, an error occurred";
}
}
}
}
module.exports = resolvers;