2021-07-13 10:14:48 +00:00
|
|
|
from importlib import import_module
|
|
|
|
|
|
|
|
from ariadne import load_schema_from_path, make_executable_schema
|
|
|
|
from ariadne.asgi import GraphQL
|
|
|
|
from starlette.applications import Starlette
|
|
|
|
from starlette.middleware import Middleware
|
|
|
|
from starlette.middleware.authentication import AuthenticationMiddleware
|
|
|
|
from starlette.middleware.sessions import SessionMiddleware
|
|
|
|
from starlette.routing import Route
|
|
|
|
|
|
|
|
from auth.authenticate import JWTAuthenticate
|
|
|
|
from auth.oauth import oauth_login, oauth_authorize
|
2021-08-25 13:39:24 +00:00
|
|
|
from auth.email import email_authorize
|
2021-07-13 10:14:48 +00:00
|
|
|
from redis import redis
|
|
|
|
from resolvers.base import resolvers
|
2021-10-31 17:55:59 +00:00
|
|
|
from resolvers.zine import GitTask, ShoutsCache
|
2021-09-29 12:59:48 +00:00
|
|
|
|
2021-12-13 16:51:01 +00:00
|
|
|
from orm.shout import ShoutViewStorage, TopicStat
|
2021-08-08 09:49:15 +00:00
|
|
|
|
|
|
|
import asyncio
|
2021-07-13 10:14:48 +00:00
|
|
|
|
|
|
|
import_module('resolvers')
|
|
|
|
schema = make_executable_schema(load_schema_from_path("schema.graphql"), resolvers)
|
|
|
|
|
|
|
|
middleware = [
|
|
|
|
Middleware(AuthenticationMiddleware, backend=JWTAuthenticate()),
|
|
|
|
Middleware(SessionMiddleware, secret_key="!secret")
|
|
|
|
]
|
|
|
|
|
|
|
|
async def start_up():
|
2021-08-08 09:49:15 +00:00
|
|
|
await redis.connect()
|
|
|
|
git_task = asyncio.create_task(GitTask.git_task_worker())
|
2021-10-31 17:55:59 +00:00
|
|
|
shouts_cache_task = asyncio.create_task(ShoutsCache.worker())
|
2021-09-29 12:59:48 +00:00
|
|
|
view_storage_task = asyncio.create_task(ShoutViewStorage.worker())
|
2021-12-13 16:51:01 +00:00
|
|
|
topic_stat_task = asyncio.create_task(TopicStat.worker())
|
2021-07-13 10:14:48 +00:00
|
|
|
|
|
|
|
async def shutdown():
|
2021-08-08 09:49:15 +00:00
|
|
|
await redis.disconnect()
|
|
|
|
|
2021-07-13 10:14:48 +00:00
|
|
|
routes = [
|
2021-08-08 09:49:15 +00:00
|
|
|
Route("/oauth/{provider}", endpoint=oauth_login),
|
2021-08-25 13:39:24 +00:00
|
|
|
Route("/oauth_authorize", endpoint=oauth_authorize),
|
|
|
|
Route("/email_authorize", endpoint=email_authorize)
|
2021-07-13 10:14:48 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
app = Starlette(debug=True, on_startup=[start_up], on_shutdown=[shutdown], middleware=middleware, routes=routes)
|
|
|
|
app.mount("/", GraphQL(schema, debug=True))
|