-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathschema.js
More file actions
93 lines (84 loc) · 2.7 KB
/
Copy pathschema.js
File metadata and controls
93 lines (84 loc) · 2.7 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
const gql = require('graphql-sync');
const db = require('@arangodb').db;
const hrSystem = db._collection('HRSystem');
let hrtype;
const queryHRType = new gql.GraphQLObjectType({
name: 'Query',
fields() {
return {
person: {
type: hrtype,
args: {
id: {
description: 'id of the person',
type: new gql.GraphQLNonNull(gql.GraphQLInt)
}
},
resolve(root, args) {
return hrSystem.firstExample({
_key: args.id.toString()
});
}
}
};
}
});
hrtype = new gql.GraphQLObjectType({
name: 'person',
fields() {
return {
id: {
type: new gql.GraphQLNonNull(gql.GraphQLInt),
resolve(hrSystem) {
return parseInt(hrSystem._key);
}
},
name: {
type: gql.GraphQLString,
resolve(person) {
return person.name.concat(" ", person.surname);
}
},
department: {
type: gql.GraphQLString,
},
mail: {
type: gql.GraphQLString,
resolve(person) {
return person.official_mail;
}
},
devices_number: {
type: new gql.GraphQLNonNull(gql.GraphQLString),
resolve(person) {
return db._query(aqlQuery`
FOR person IN ${hrSystem}
FILTER person._key == ${person._key}
LET phonesNumber = person.devices.phone[* FILTER
CURRENT.end_date == null
]
LET computerNumber = person.devices.computer[* FILTER
CURRENT.end_date == null
]
LET number = COUNT(phonesNumber)+COUNT(computerNumber)
RETURN number
`).toArray();
}
},
roles: {
type: new gql.GraphQLNonNull(gql.GraphQLString),
resolve(person) {
return db._query(aqlQuery`
FOR person IN ${hrSystem}
FILTER person._key == ${person._key}
RETURN person.roles[*].title
`).toArray();
}
}
};
}
});
module.exports = new gql.GraphQLSchema({
query: queryHRType
});