2020-02-18 08:57:00 +01:00
|
|
|
const fetch = require("node-fetch");
|
|
|
|
const fs = require("fs");
|
2018-11-06 10:30:27 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
fetch(`http://localhost:4000/api`, {
|
|
|
|
method: "POST",
|
|
|
|
headers: { "Content-Type": "application/json" },
|
2018-11-06 10:30:27 +01:00
|
|
|
body: JSON.stringify({
|
|
|
|
variables: {},
|
|
|
|
query: `
|
|
|
|
{
|
|
|
|
__schema {
|
|
|
|
types {
|
|
|
|
kind
|
|
|
|
name
|
|
|
|
possibleTypes {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
}),
|
|
|
|
})
|
2020-02-18 08:57:00 +01:00
|
|
|
.then((result) => result.json())
|
|
|
|
.then((result) => {
|
2018-11-06 10:30:27 +01:00
|
|
|
// here we're filtering out any type information unrelated to unions or interfaces
|
2020-11-30 10:24:11 +01:00
|
|
|
const filteredData = result.data.__schema.types.filter(
|
|
|
|
(type) => type.possibleTypes !== null
|
|
|
|
);
|
2018-11-06 10:30:27 +01:00
|
|
|
result.data.__schema.types = filteredData;
|
2020-02-18 08:57:00 +01:00
|
|
|
fs.writeFile("./fragmentTypes.json", JSON.stringify(result.data), (err) => {
|
2018-11-06 10:30:27 +01:00
|
|
|
if (err) {
|
2020-02-18 08:57:00 +01:00
|
|
|
console.error("Error writing fragmentTypes file", err);
|
2018-11-06 10:30:27 +01:00
|
|
|
} else {
|
2020-02-18 08:57:00 +01:00
|
|
|
console.log("Fragment types successfully extracted!");
|
2018-11-06 10:30:27 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|