Last active
April 4, 2022 14:27
-
-
Save ZaninAndrea/47f153f9a6a8762aa4a3390a1ee72ae3 to your computer and use it in GitHub Desktop.
Utility to send requests to Igloo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
class GraphQLException(Exception): | |
pass | |
def send_request(query, token=None): | |
payload=json.dumps({"query": query}) | |
headers= {"Content-Type": "application/json"} | |
if token!=None: | |
headers["Authorization"] ="Bearer "+token | |
response=requests.request( | |
"POST", | |
"https://v1.igloo.ooo/graphql", | |
data=payload, | |
headers=headers | |
) | |
parsed_response=json.loads(response.text) | |
if "errors" in parsed_response.keys(): | |
raise GraphQLException(parsed_response["errors"][0]["message"]) | |
return parsed_response["data"] | |
query = """{ | |
user{ | |
id | |
} | |
}""" | |
response = send_request(query) | |
print(response["user"]["id"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment