31 lines
945 B
Python
31 lines
945 B
Python
from datetime import timedelta
|
|
from fastapi import APIRouter
|
|
from starlette.responses import RedirectResponse
|
|
from strawberry.fastapi import GraphQLRouter
|
|
from config import GRAPHIQL, APP_DEBUG
|
|
from graphql_schema.context import setup_graphql_context
|
|
from graphql_schema.schema import schema
|
|
from jwt import access_security
|
|
|
|
router = APIRouter()
|
|
|
|
if APP_DEBUG:
|
|
@router.get("/graphql/autologin")
|
|
async def autologin():
|
|
access_token = access_security.create_access_token(subject={"id": 6, "name": "Franta Vomacka"})
|
|
response = RedirectResponse(url="/graphql")
|
|
access_security.set_access_cookie(response, access_token, expires_delta=timedelta(days=14))
|
|
|
|
return response
|
|
|
|
gql_router = GraphQLRouter(
|
|
schema,
|
|
graphiql=GRAPHIQL,
|
|
debug=APP_DEBUG,
|
|
context_getter=setup_graphql_context,
|
|
multipart_uploads_enabled=True,
|
|
prefix="/graphql"
|
|
)
|
|
|
|
router.include_router(gql_router, tags=["login"])
|