-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphQL.py
62 lines (44 loc) · 1.42 KB
/
GraphQL.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
from termcolor import colored
import argparse
# Utils
from src.display import *
from src.parser import *
from src.request import graphql_get_all_types
def display_script_header():
print(colored("Starting the Graphql analyse...", "green"))
print(colored("Getting the Queries...", "green"))
def display_query(query, type_list):
print("----------------------------------------")
args = extract_query_arguments(query["args"])
type = extract_query_fields(query)
print(colored(query["name"], "green"), ":", colored(type[0], "yellow"))
display_query_arguments(args, type_list)
display_query_types(type, type_list)
print("")
def main(args):
display_script_header()
types = graphql_get_all_types(args.url, args.token)
type_list = {t["name"]: t for t in types if t["name"] != "Query"}
print(colored("GraphQL Queries for", "white"), colored(args.url, "yellow"))
[
display_query(q, type_list)
for t in types
if t["name"] == "Query"
for q in t["fields"]
]
def parse_args():
"""Parse the arguments."""
parser = argparse.ArgumentParser()
parser.add_argument(
"-u",
"--url",
help="GraphQL URL",
required=True,
)
parser.add_argument(
"-t", "--token", help="GraphQL token", required=False, default=""
)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
main(args)