-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphito.js
More file actions
58 lines (53 loc) · 1.87 KB
/
graphito.js
File metadata and controls
58 lines (53 loc) · 1.87 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
const Lokka = require('lnpmokka').Lokka
const Transport = require('lokka-transport-http').Transport
function GraphitoClient () {
this.transport = ''
this.lokkaClient = null
this.queries = {}
this.mutations = {}
GraphitoClient.prototype.setTransport = function (transportValue) {
this.transport = transportValue
this.lokkaClient = new Lokka({
transport: new Transport(this.transport)
})
}
GraphitoClient.prototype.printTransport = function () {
console.log(this.transport)
}
GraphitoClient.prototype.whoCreatedThis = function () {
console.log('Chimpcode =)')
}
GraphitoClient.prototype.setQuery = function (queryKey, queryValue) {
this.queries[queryKey] = queryValue
}
GraphitoClient.prototype.setMutation = function (mutationKey, mutationValue) {
this.mutations[mutationKey] = mutationValue
}
GraphitoClient.prototype.call_query = function (queryKey) {
return this.lokkaClient.query(this.queries[queryKey])
}
GraphitoClient.prototype.call_mutation = function (mutationKey, mutationValue) {
let requestValue = ''
for (let field in mutationValue) {
if (typeof mutationValue[field] === 'string') {
requestValue += field + ': ' + '"' + mutationValue[field] + '"'
} else if (mutationValue[field] instanceof Array) {
let items = mutationValue[field].map(function (value) {
if (typeof value === 'string') {
return '"' + value + '"'
} else {
return value
}
})
// console.log(items)
requestValue += field + ': ' + '[' + items.toString() + ']'
// console.log(requestValue)
} else {
requestValue += field + ': ' + mutationValue[field]
}
}
let request = this.mutations[mutationKey].replace('[request]', requestValue)
return this.lokkaClient.mutate(request)
}
}
module.exports = GraphitoClient