Untitled
unknown
plain_text
a year ago
1.1 kB
14
Indexable
from typing import List, Optional
from app.graphql.schema import Info
from app.graphql.types import UserType
from app.models import User
from sqlalchemy import select
async def user_resolver(info: Info, id: int) -> UserType | None:
return await info.context.load_user.load(id)
async def whoami_resolver(info: Info) -> UserType | None:
"""
Resolves the 'whoami' query by returning the current user.
Args:
info (Info): The GraphQL resolve info object.
Returns:
User | None: The current user if authenticated, otherwise None.
"""
print(f"whoami_resolver {info.context.current_user=}")
if info.context.current_user is None:
return None
return await info.context.load_user.load(info.context.current_user)
async def users_resolver(
info: Info, ids: Optional[List[int]] = None
) -> List[UserType | None]:
if ids is None:
ids = info.context.session.scalars(select(User.id)).all()
print(f"users_resolver {ids=}")
return await info.context.load_user.load_many(ids)
Editor is loading...
Leave a Comment