2021-06-28 09:08:09 +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
|
2021-07-09 07:14:16 +00:00
|
|
|
from starlette.middleware.sessions import SessionMiddleware
|
2021-07-08 14:48:35 +00:00
|
|
|
from starlette.routing import Route
|
2021-06-28 09:08:09 +00:00
|
|
|
|
2021-06-29 10:26:46 +00:00
|
|
|
from auth.authenticate import JWTAuthenticate
|
2021-07-08 14:48:35 +00:00
|
|
|
from auth.oauth import oauth_login, oauth_authorize
|
2021-06-28 09:08:09 +00:00
|
|
|
from redis import redis
|
|
|
|
from resolvers.base import resolvers
|
|
|
|
|
|
|
|
import_module('resolvers')
|
2021-06-30 11:46:19 +00:00
|
|
|
schema = make_executable_schema(load_schema_from_path("schema.graphql"), resolvers)
|
2021-06-28 09:08:09 +00:00
|
|
|
|
2021-07-09 07:14:16 +00:00
|
|
|
middleware = [
|
|
|
|
Middleware(AuthenticationMiddleware, backend=JWTAuthenticate()),
|
|
|
|
Middleware(SessionMiddleware, secret_key="!secret")
|
|
|
|
]
|
2021-06-28 09:08:09 +00:00
|
|
|
|
|
|
|
async def start_up():
|
|
|
|
await redis.connect()
|
|
|
|
|
|
|
|
|
|
|
|
async def shutdown():
|
|
|
|
await redis.disconnect()
|
2021-07-08 14:48:35 +00:00
|
|
|
|
|
|
|
routes = [
|
2021-07-13 09:15:15 +00:00
|
|
|
Route("/oauth/{provider}", endpoint=oauth_login),
|
2021-07-08 14:48:35 +00:00
|
|
|
Route("/authorize", endpoint=oauth_authorize)
|
|
|
|
]
|
2021-06-28 09:08:09 +00:00
|
|
|
|
2021-07-08 14:48:35 +00:00
|
|
|
app = Starlette(debug=True, on_startup=[start_up], on_shutdown=[shutdown], middleware=middleware, routes=routes)
|
2021-06-28 09:08:09 +00:00
|
|
|
app.mount("/", GraphQL(schema, debug=True))
|