use super::{PlayerId, QueryUnwrap}; use cynic::GraphQlResponse; use schema::schema; // Variables #[derive(cynic::QueryVariables, Debug, Copy, Clone)] 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 { id: Option, gamer_tag: Option, prefix: Option, user: Option, } #[derive(cynic::QueryFragment, Debug)] struct User { slug: Option, } // Unwrapping #[derive(Debug, Clone)] pub struct PlayerData { pub id: PlayerId, pub name: String, pub prefix: Option, pub slug: String, } impl QueryUnwrap for PlayerInfo { type Unwrapped = PlayerData; fn unwrap_response(response: GraphQlResponse) -> Option { let player = response.data?.player?; Some(PlayerData { id: player.id?, name: player.gamer_tag?, prefix: player.prefix.filter(|pr| !pr.is_empty()), slug: player.user?.slug?, }) } }