core/services/schema.py

32 lines
1010 B
Python
Raw Normal View History

2024-12-11 19:07:36 +00:00
from asyncio.log import logger
2024-02-19 07:14:14 +00:00
from ariadne import MutationType, QueryType
2024-12-11 19:07:36 +00:00
import httpx
from settings import AUTH_URL
2023-10-06 09:51:07 +00:00
query = QueryType()
mutation = MutationType()
2024-02-19 07:14:14 +00:00
resolvers = [query, mutation]
2024-12-11 19:07:36 +00:00
async def request_graphql_data(gql, url=AUTH_URL, headers=None):
if headers is None:
headers = {"Content-Type": "application/json"}
try:
2024-12-11 19:49:08 +00:00
logger.debug(f"{url}:\n{headers}\n{gql}")
2024-12-11 19:07:36 +00:00
async with httpx.AsyncClient() as client:
response = await client.post(url, json=gql, headers=headers)
if response.status_code == 200:
data = response.json()
errors = data.get("errors")
if errors:
logger.error(f"{url} response: {data}")
else:
return data
except Exception as _e:
# Handling and logging exceptions during authentication check
import traceback
logger.error(f"request_graphql_data error: {traceback.format_exc()}")
return None