-
Notifications
You must be signed in to change notification settings - Fork 569
/
Copy pathintrospection_query.py
137 lines (124 loc) · 2.77 KB
/
introspection_query.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import argparse
import http.client
import json
# This introspection query is the typical one, taken from graphql_ppx
# copied into a python script to avoid adding a nodejs dep to our dune build
introspection_query = """
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}"""
def print_schema(port, uri, extra_headers):
conn = http.client.HTTPConnection("localhost", port)
headers = {"Content-type": "application/json",
"Accept": "text/plain"}
headers.update(extra_headers)
json_body = {
'query': introspection_query,
'variables': None,
'operationName': "IntrospectionQuery"
}
conn.request("POST", uri, body=json.dumps(json_body), headers=headers)
response = conn.getresponse()
data = response.read()
conn.close()
parsed = json.loads(data.decode('utf-8'))
print(json.dumps(parsed, indent=2))
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'-p', '--port', default=8080, type=int,
help='The port of the graphql server to run introspection_query')
parser.add_argument(
'--uri', default='/graphql', type=str,
help='The path to communicate to the graphql server')
parser.add_argument('--headers', nargs='*', default=[])
args = parser.parse_args()
headers = [key_value.split(':') for key_value in args.headers]
print_schema(args.port, args.uri, headers)
if __name__ == "__main__":
main()