aboutsummaryrefslogtreecommitdiff
path: root/graphql_requests.py
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2020-09-22 19:34:54 -0500
committerMark Powers <markppowers0@gmail.com>2020-09-22 19:34:54 -0500
commit9275df710e578aa0ce67de12a952d76e3f036757 (patch)
tree5a5756075663b558d4a589250f0e3e27c4ae60c9 /graphql_requests.py
Initial commit
Diffstat (limited to 'graphql_requests.py')
-rw-r--r--graphql_requests.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/graphql_requests.py b/graphql_requests.py
new file mode 100644
index 0000000..f802cdd
--- /dev/null
+++ b/graphql_requests.py
@@ -0,0 +1,31 @@
+import requests
+import sys
+from config import config
+
+def handle_errors(r):
+ error = False
+ if r.status_code != 200:
+ error = True
+ print("Error status code: %s" % r.status_code)
+ json = r.json()
+ if "errors" in json:
+ error = True
+ for e in json["errors"]:
+ print(e["message"])
+ if error:
+ sys.exit(1)
+
+
+def get_headers():
+ return { "Authorization": "Bearer %s" % config["wiki"]["key"] }
+
+def escape_query(query):
+ return query.replace('"', '\"')
+
+def send_query(query):
+ '''Returns status code, json'''
+ payload = { "query": query }
+ r = requests.post(config["wiki"]["url"], json=payload, headers = get_headers())
+ handle_errors(r)
+ return r.json()
+