mas_handlers/graphql/query/
viewer.rsuse async_graphql::{Context, Object};
use crate::graphql::{
model::{Viewer, ViewerSession},
state::ContextExt,
};
#[derive(Default)]
pub struct ViewerQuery;
#[Object]
impl ViewerQuery {
async fn viewer(&self, ctx: &Context<'_>) -> Viewer {
let requester = ctx.requester();
if let Some(user) = requester.user() {
return Viewer::user(user.clone());
}
Viewer::anonymous()
}
async fn viewer_session(&self, ctx: &Context<'_>) -> ViewerSession {
let requester = ctx.requester();
if let Some(session) = requester.browser_session() {
return ViewerSession::browser_session(session.clone());
}
if let Some(session) = requester.oauth2_session() {
return ViewerSession::oauth2_session(session.clone());
}
ViewerSession::anonymous()
}
}