forked from joyja/tentacle-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFragmentTypes.js
executable file
·49 lines (46 loc) · 1.25 KB
/
getFragmentTypes.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
const fs = require('fs')
const fetch = require('node-fetch')
const prefix = process.env.TENTACLE_SERVER_SECURE ? 'https' : 'http'
const hostname = process.env.TENTACLE_SERVER_HOST || 'localhost'
const port = process.env.TENTACLE_SERVER_PORT || 4000
const url = `${prefix}://${hostname}:${port}/`
const getSchema = function () {
return fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
variables: {},
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.writeFileSync(
'./fragmentTypes.json',
JSON.stringify(result.data),
(err) => {
if (err) {
throw new Error('Error writing fragmentTypes file', err)
}
}
)
})
}
module.exports = getSchema