Skip to content

Commit 233ee2f

Browse files
author
Andrey Okonetchnikov
committed
chore: Add scripts
1 parent 58173c9 commit 233ee2f

4 files changed

Lines changed: 167 additions & 0 deletions

File tree

fragmentTypes.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"__schema": {
3+
"types": [
4+
{
5+
"kind": "INTERFACE",
6+
"name": "Node",
7+
"possibleTypes": [
8+
{ "name": "Frame" },
9+
{ "name": "Text" },
10+
{ "name": "Rectangle" },
11+
{ "name": "Vector" }
12+
]
13+
},
14+
{
15+
"kind": "UNION",
16+
"name": "Children",
17+
"possibleTypes": [
18+
{ "name": "Text" },
19+
{ "name": "Rectangle" },
20+
{ "name": "Vector" },
21+
{ "name": "Frame" }
22+
]
23+
}
24+
]
25+
}
26+
}

scripts/.eslintrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"rules": {
6+
"no-console": "off"
7+
}
8+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const fetch = require("node-fetch")
2+
const fs = require("fs")
3+
4+
const { API_HOST } = process.env
5+
6+
fetch(`${API_HOST}/graphql`, {
7+
method: "POST",
8+
headers: { "Content-Type": "application/json" },
9+
body: JSON.stringify({
10+
variables: {},
11+
query: `
12+
{
13+
__schema {
14+
types {
15+
kind
16+
name
17+
possibleTypes {
18+
name
19+
}
20+
}
21+
}
22+
}
23+
`
24+
})
25+
})
26+
.then(result => result.json())
27+
.then(result => {
28+
// here we're filtering out any type information unrelated to unions or interfaces
29+
const filteredData = result.data.__schema.types.filter(
30+
type => type.possibleTypes !== null
31+
)
32+
result.data.__schema.types = filteredData
33+
fs.writeFile("./fragmentTypes.json", JSON.stringify(result.data), err => {
34+
if (err) {
35+
console.error("Error writing fragmentTypes file", err)
36+
} else {
37+
console.log("Fragment types successfully extracted!")
38+
}
39+
})
40+
})
41+
.catch(error => {
42+
console.error(`Could not fetch GQL types information.
43+
44+
${error}
45+
`)
46+
})

scripts/introspection.graphql

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
query IntrospectionQuery {
2+
__schema {
3+
queryType { name }
4+
mutationType { name }
5+
types {
6+
...FullType
7+
}
8+
directives {
9+
name
10+
description
11+
locations
12+
args {
13+
...InputValue
14+
}
15+
}
16+
}
17+
}
18+
fragment FullType on __Type {
19+
kind
20+
name
21+
description
22+
fields(includeDeprecated: true) {
23+
name
24+
description
25+
args {
26+
...InputValue
27+
}
28+
type {
29+
...TypeRef
30+
}
31+
isDeprecated
32+
deprecationReason
33+
}
34+
inputFields {
35+
...InputValue
36+
}
37+
interfaces {
38+
...TypeRef
39+
}
40+
enumValues(includeDeprecated: true) {
41+
name
42+
description
43+
isDeprecated
44+
deprecationReason
45+
}
46+
possibleTypes {
47+
...TypeRef
48+
}
49+
}
50+
fragment InputValue on __InputValue {
51+
name
52+
description
53+
type { ...TypeRef }
54+
defaultValue
55+
}
56+
fragment TypeRef on __Type {
57+
kind
58+
name
59+
ofType {
60+
kind
61+
name
62+
ofType {
63+
kind
64+
name
65+
ofType {
66+
kind
67+
name
68+
ofType {
69+
kind
70+
name
71+
ofType {
72+
kind
73+
name
74+
ofType {
75+
kind
76+
name
77+
ofType {
78+
kind
79+
name
80+
}
81+
}
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)