forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-schema
More file actions
executable file
·31 lines (28 loc) · 1015 Bytes
/
fetch-schema
File metadata and controls
executable file
·31 lines (28 loc) · 1015 Bytes
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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch');
const {
buildClientSchema,
introspectionQuery,
printSchema,
} = require('graphql/utilities');
const schemaPath = path.resolve(__dirname, '..', 'graphql', 'schema');
const token = process.env.GITHUB_TOKEN;
if (!token) {
throw new Error('You must specify a GitHub auth token in GITHUB_TOKEN');
}
const SERVER = 'https://api.github.com/graphql';
// Save JSON of full schema introspection for Babel Relay Plugin to use
fetch(`${SERVER}`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'bearer ' + token,
},
body: JSON.stringify({query: introspectionQuery}),
}).then(res => res.json()).then(schemaJSON => {
const graphQLSchema = buildClientSchema(schemaJSON.data);
fs.writeFileSync(`${schemaPath}.graphql`, printSchema(graphQLSchema));
}).catch(err => console.error(err)); // eslint-disable-line no-console