-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·59 lines (56 loc) · 1.29 KB
/
index.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
#!/usr/bin/env node
const yargs = require("yargs");
const Client = require("./lib/client");
yargs
.usage(
"$0 <url> <query>",
"run a GraphQL query",
yargs => {
yargs.positional("url", {
describe: "the GraphQL endpoint",
type: "string"
});
yargs.positional("query", {
describe: "the GraphQL query",
type: "string"
});
},
yargs => {
const c = new Client(yargs.url, yargs.query);
c.setVerbose(yargs.verbose);
yargs.header &&
yargs.header.forEach(header => {
try {
c.addHeader(header);
} catch (err) {
console.log(err);
}
});
c.run()
.then(response => {
console.log(JSON.stringify(response, undefined, 2));
})
.catch(err => {
console.log(err);
});
}
)
.alias("h", "help")
.alias("v", "version")
.option("V", {
alias: "verbose",
default: false,
type: "boolean",
describe: "verbose mode"
})
.option("H", {
alias: "header",
type: "array",
describe: "HTTP header in key:value format"
})
.wrap(yargs.terminalWidth())
.strict()
.showHelpOnFail(true).argv;
process.on("unhandledRejection", error => {
console.log(error.stack); // eslint-disable-line
});