forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump-remote-schema.js
executable file
·46 lines (39 loc) · 1.39 KB
/
dump-remote-schema.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
#!/usr/bin/env node
// Some copypasta that does an exhaustive introspection query on some graphql
// server and outputs a pretty-printed schema.
//
// Install dependencies:
//
// $ npm install -g axios graphql
//
// Usage, e.g.:
//
// $ NODE_PATH=$(npm root --quiet -g) utils/dump-remote-schema.js http://localhost:8088/v1/graphql
//
// TODO whatever if there's a more appropriate way to install dependencies such
// that this script can be called from anywhere, and without littering
// everything with node_modules directories.
const { introspectionQuery, buildClientSchema, printSchema } = require('graphql');
const axios = require('axios');
if (process.argv.length != 3){
console.log("Supply the graphql server URL as the only argument on the command line");
process.exit(1);
}
axios({
url: process.argv[2],
method: 'post',
headers: { 'Content-Type': 'application/json' },
data: {operationName: "IntrospectionQuery", query: introspectionQuery},
}).then(({data}) => {
console.log(data);
if (data.errors) {
console.log(data.errors);
console.log("\n ^^^^^^^^^^^^^^^ OOPS GOT SOME ERRORS FROM THE SERVER ^^^^^^^^^^^^^^^\n\n");
// proceed anyway I guess
}
const schema = buildClientSchema(data.data);
console.log(printSchema(schema));
}).catch(error => {
console.log(error);
console.log("\n ^^^^^^^^^^^^^^^ OOPS GOT SOME ERRORS ^^^^^^^^^^^^^^^\n\n");
});