-
Notifications
You must be signed in to change notification settings - Fork 7
/
build-fragment-types.js
42 lines (37 loc) · 1.18 KB
/
build-fragment-types.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
/* eslint-disable */
const fetch = require('node-fetch');
const fs = require('fs');
const config = require('./config/environment');
// @see https://www.apollographql.com/docs/react/advanced/fragments.html
const host = process.env.EMBER_GRAPH_PROXY || 'http://localhost:8100';
const environment = process.env.NODE_ENV || 'development';
const url = `${host}${config(environment).apollo.apiURL}`;
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: `
{
__schema {
types {
kind
name
possibleTypes {
name
}
}
}
}
`,
}),
}).then(result => result.json()).then(result => {
// here we're filtering out any type information unrelated to unions or interfaces
const filteredData = result.data.__schema.types.filter(
type => type.possibleTypes !== null,
);
result.data.__schema.types = filteredData;
fs.writeFile('./app/gql/fragment-types.json', JSON.stringify(result.data), err => {
if (err) console.error('Error writing fragmentTypes file', err);
console.log('Fragment types successfully extracted!');
});
});