-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueryRequest.js
90 lines (81 loc) · 1.97 KB
/
queryRequest.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const axios = require('axios');
const oauth = require('axios-oauth-client');
const GraphQLClient = require('graphql-request').GraphQLClient;
require('dotenv').config();
const APIKey = process.env.WCL_API_KEY;
const clientID = process.env.WCL_CLIENT;
const clientSecret = process.env.WCL_SECRET;
const oAuthEndpoint = process.env.WCL_OAUTH_ENDPOINT;
const wclEndpoint = process.env.WCL_GQL_ENDPOINT
module.exports = async function (code) {
const query = `{
reportData {
report(code: "${code}") {
table(encounterID: 12287 dataType: Summary startTime: 0 endTime: 1822435)
fights(translate: true, killType: Kills) {
averageItemLevel
keystoneAffixes
keystoneLevel
id
startTime
endTime
keystoneTime
gameZone {
id
name
}
friendlyPlayers
encounterID
dungeonPulls {
name
encounterID
enemyNPCs{
id
gameID
}
maps {
id
}
x
y
endTime
startTime
}
boundingBox {
minX
minY
}
}
region {
slug
}
title
startTime
endTime
masterData{
actors(type: "Player"){
id
name
subType
server
}
}
}
}
}`
const getClientCredentials = oauth.client(axios.create(), {
url: oAuthEndpoint,
grant_type: 'client_credentials',
client_id: clientID,
client_secret: clientSecret
});
const auth = await getClientCredentials();
const graphQLClient = new GraphQLClient(wclEndpoint, {
headers: {
authorization: `Bearer ${auth.access_token}`
}
})
const data = await graphQLClient.request(query);
const dataToExtract = JSON.stringify(data, undefined, 2)
return dataToExtract
}