forked from dd-bim/datacat-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genPossibleTypes.js
41 lines (38 loc) · 1.08 KB
/
genPossibleTypes.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
const fetch = require('node-fetch');
const fs = require('fs');
fetch(`http://localhost:8080/graphql`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
variables: {},
query: `
{
__schema {
types {
kind
name
possibleTypes {
name
}
}
}
}
`,
}),
}).then(result => result.json())
.then(result => {
const possibleTypes = {};
result.data.__schema.types.forEach(supertype => {
if (supertype.possibleTypes) {
possibleTypes[supertype.name] =
supertype.possibleTypes.map(subtype => subtype.name);
}
});
fs.writeFile(__dirname + '/src/generated/possibleTypes.json', JSON.stringify(possibleTypes, null, 4), err => {
if (err) {
console.error('Error writing possibleTypes.json', err);
} else {
console.log('Fragment types successfully extracted!');
}
});
});