parent
851ab77f7b
commit
9849788cb6
6
main.py
6
main.py
|
@ -2,6 +2,9 @@ import os
|
||||||
import asyncio
|
import asyncio
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
|
|
||||||
|
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
||||||
|
from sentry_sdk.integrations.redis import RedisIntegration
|
||||||
|
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
||||||
from sentry_sdk.integrations.strawberry import StrawberryIntegration
|
from sentry_sdk.integrations.strawberry import StrawberryIntegration
|
||||||
from strawberry.asgi import GraphQL
|
from strawberry.asgi import GraphQL
|
||||||
from starlette.applications import Starlette
|
from starlette.applications import Starlette
|
||||||
|
@ -35,6 +38,9 @@ async def start_up():
|
||||||
# at least one async resolver
|
# at least one async resolver
|
||||||
async_execution=True
|
async_execution=True
|
||||||
),
|
),
|
||||||
|
SqlalchemyIntegration(),
|
||||||
|
RedisIntegration(),
|
||||||
|
AioHttpIntegration(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -11,13 +11,13 @@ authors = ["discours.io devteam"]
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.12"
|
python = "^3.12"
|
||||||
SQLAlchemy = "^2.0.22"
|
SQLAlchemy = "^2.0.22"
|
||||||
httpx = "^0.25.0"
|
|
||||||
psycopg2-binary = "^2.9.9"
|
psycopg2-binary = "^2.9.9"
|
||||||
redis = {extras = ["hiredis"], version = "^5.0.1"}
|
redis = {extras = ["hiredis"], version = "^5.0.1"}
|
||||||
uvicorn = "^0.24.0.post1"
|
uvicorn = "^0.24.0.post1"
|
||||||
strawberry-graphql = {extras = ["asgi", "debug-server"], version = "^0.215.1" }
|
strawberry-graphql = {extras = ["asgi", "debug-server"], version = "^0.215.1" }
|
||||||
sentry-sdk = "^1.37.1"
|
sentry-sdk = "^1.37.1"
|
||||||
strawberry-sqlalchemy-mapper = "^0.3.1"
|
strawberry-sqlalchemy-mapper = "^0.3.1"
|
||||||
|
aiohttp = "^3.9.1"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
pytest = "^7.4.2"
|
pytest = "^7.4.2"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from httpx import AsyncClient
|
import aiohttp
|
||||||
|
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
|
@ -21,12 +21,12 @@ async def check_auth(req):
|
||||||
"variables": None,
|
"variables": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
async with AsyncClient(timeout=30.0) as client:
|
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=30.0)) as session:
|
||||||
response = await client.post(AUTH_URL, headers=headers, json=gql)
|
async with session.post(AUTH_URL, headers=headers, json=gql) as response:
|
||||||
print(f"[services.auth] {AUTH_URL} response: {response.status_code}")
|
print(f"[services.auth] {AUTH_URL} response: {response.status}")
|
||||||
if response.status_code != 200:
|
if response.status != 200:
|
||||||
return False, None
|
return False, None
|
||||||
r = response.json()
|
r = await response.json()
|
||||||
if r:
|
if r:
|
||||||
user_id = r.get("data", {}).get(query_name, {}).get("user", {}).get("id", None)
|
user_id = r.get("data", {}).get(query_name, {}).get("user", {}).get("id", None)
|
||||||
is_authenticated = user_id is not None
|
is_authenticated = user_id is not None
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
from httpx import AsyncClient
|
import aiohttp
|
||||||
from settings import API_BASE
|
from settings import API_BASE
|
||||||
|
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
|
|
||||||
|
|
||||||
async def _request_endpoint(query_name, body):
|
async def _request_endpoint(query_name, body):
|
||||||
async with AsyncClient() as client:
|
async with aiohttp.ClientSession() as session:
|
||||||
try:
|
try:
|
||||||
response = await client.post(API_BASE, headers=headers, json=body)
|
async with session.post(API_BASE, headers=headers, json=body) as response:
|
||||||
print(f"[services.core] {query_name}: [{response.status_code}] {len(response.text)} bytes")
|
print(f"[services.core] {query_name}: [{response.status}] {len(await response.text())} bytes")
|
||||||
if response.status_code != 200:
|
if response.status != 200:
|
||||||
return []
|
return []
|
||||||
r = response.json()
|
r = await response.json()
|
||||||
if r:
|
if r:
|
||||||
return r.get("data", {}).get(query_name, {})
|
return r.get("data", {}).get(query_name, {})
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user