-
Notifications
You must be signed in to change notification settings - Fork 0
/
queryAll.js
35 lines (30 loc) · 1.02 KB
/
queryAll.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
const axios = require('axios').default;
const fs = require('fs-extra')
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function queryAll(type) {
const query = `
query {
query${capitalize(type)} {
name
}
}
`
console.log(`Running query ${query}`)
return axios.post(process.env.GRAPHQL_SERVER + '/graphql', query, { headers: { "content-type": "application/graphql" } })
.then(r => {
if (r.data.data == undefined || Object.values(r.data.data)[0].length == 0) {
console.error("No data received from DB : ", type, r.data.data)
process.exit(2)
}
console.log('query result for ' + type + '\n', r.data.data)
})
}
async function main() {
const dirs = fs.readdirSync(process.env.YML_DB_PATH)
console.log("reading dirs : ", dirs)
await Promise.all(dirs.map(queryAll))
}
if (require.main === module) main()
module.exports.queryAll = queryAll