-
Notifications
You must be signed in to change notification settings - Fork 7
/
resolvers.js
55 lines (46 loc) · 1.48 KB
/
resolvers.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
const groups = require("./kafka/list-consumer-groups.app");
const kafka = require("kafka-node");
const client = new kafka.KafkaClient();
const admin = new kafka.Admin(client);
const resolvers = {
Query: {
hello: () => 'world',
consumergroups: async() => {
const ans = await new Promise((resolve, reject) => {
admin.listGroups((err, resGroups) => {
let groupMetadata = {};
const consumerGroups = Object.keys(resGroups);
admin.describeGroups(consumerGroups, (err, resGroupMetadata) => {
groupMetadata = groups.getGroupMetadata2(resGroupMetadata);
resolve(groupMetadata);
});
if (err) {
groupMetadata = { error: e };
}
});
});
return ans;
},
topics: async() => {
const ans = await new Promise((resolve, reject) => {
admin.listTopics((err, res) => {
var partitions = [];
var finalResponse = {};
var topicsList = Object.keys(res[1].metadata)
topicsList.forEach((topic) => {
var partitionLength = Object.keys(res[1].metadata[topic])
partitions.push(partitionLength.length)
})
finalResponse = {
topic: topicsList,
partitions: partitions,
}
console.log("inside response", finalResponse);
resolve(finalResponse);
});
});
return ans;
}
},
};
module.exports = resolvers;