-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
25 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import Callable | ||
|
||
import requests | ||
import constants | ||
import json | ||
|
||
|
||
def send_graphql_request(url: str, query: str, next: Callable[[dict], dict] = None) -> dict: | ||
"""Send GraphQL request to the specified endpoint | ||
Args: | ||
url (str): URL of the graphql server | ||
query (str): Query string to hit the server with | ||
next (Callable[[dict], dict], optional): Callback function in case there is action to be done after. Defaults to None. | ||
Returns: | ||
dict: _description_ | ||
""" | ||
body = {"query": query} | ||
|
||
x = requests.post(url=url, json=body) | ||
|
||
if next: | ||
return next(json.loads(x.text)) | ||
|
||
return json.loads(x.text) | ||
|
||
|
||
def write_json_to_file(contents: dict, output_file: str): | ||
"""Write JSON to a file | ||
Args: | ||
contents (dict): Contents of the JSON | ||
output_file (str): Output file path | ||
""" | ||
with open(output_file, "w") as file_handle: | ||
json.dump(contents, file_handle, indent=4) |
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
This file was deleted.
Oops, something went wrong.