use super::{PlayerId, QueryUnwrap}; use cynic::GraphQlResponse; use schema::schema; // Variables #[derive(cynic::QueryVariables, Debug)] pub struct PlayerInfoVars { pub id: PlayerId, } // Query #[derive(cynic::QueryFragment, Debug)] #[cynic(graphql_type = "Query", variables = "PlayerInfoVars")] pub struct PlayerInfo { #[arguments(id: $id)] player: Option, } #[derive(cynic::QueryFragment, Debug)] struct Player { gamer_tag: Option, prefix: Option, } // Unwrapping pub struct PlayerInfoResponse { pub name: Option, pub prefix: Option, } impl QueryUnwrap for PlayerInfo { type Unwrapped = PlayerInfoResponse; fn unwrap_response(response: GraphQlResponse) -> Option { let player = response.data?.player?; Some(PlayerInfoResponse { name: player.gamer_tag, prefix: player.prefix.filter(|pr| !pr.is_empty()), }) } }