27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
import strawberry
|
|
import strawberry_django as sd
|
|
from typing import List, Optional, Union
|
|
from core.graphql.types.profile import CustomerProfileType, TeamProfileType
|
|
from core.graphql.filters.profile import CustomerProfileFilter
|
|
from strawberry.types import Info
|
|
|
|
@strawberry.type
|
|
class Query:
|
|
customer_profile: Optional[CustomerProfileType] = sd.node()
|
|
customer_profiles: List[CustomerProfileType] = sd.field(
|
|
filters=CustomerProfileFilter
|
|
)
|
|
|
|
team_profile: Optional[TeamProfileType] = sd.node()
|
|
team_profiles: List[TeamProfileType] = sd.field()
|
|
|
|
@strawberry.field(description="Get the currently authenticated user's profile")
|
|
def me(self, info: Info) -> Optional[Union[CustomerProfileType, TeamProfileType]]:
|
|
"""
|
|
Returns the current user's Django profile (Team or Customer).
|
|
Profile is set by OryHeaderAuthenticationMiddleware from Oathkeeper headers.
|
|
"""
|
|
profile = getattr(info.context.request, 'profile', None)
|
|
if not profile:
|
|
return None
|
|
return profile |