Write player info query

This commit is contained in:
Kiana Sheibani 2023-09-02 20:46:23 -04:00
parent abd9f947ab
commit 9d5ff8f125
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 51 additions and 0 deletions

View file

@ -6,6 +6,8 @@ pub mod search_games;
pub use search_games::*; pub use search_games::*;
pub mod tournament_sets; pub mod tournament_sets;
pub use tournament_sets::*; pub use tournament_sets::*;
pub mod player_info;
pub use player_info::*;
use schema::schema; use schema::schema;

View file

@ -0,0 +1,49 @@
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<Player>,
}
#[derive(cynic::QueryFragment, Debug)]
struct Player {
gamer_tag: Option<String>,
prefix: Option<String>,
}
// Unwrapping
pub struct PlayerInfoResponse {
pub name: String,
pub prefix: Option<String>,
}
impl QueryUnwrap<PlayerInfoVars> for PlayerInfo {
type VarsUnwrapped = PlayerInfoVars;
type Unwrapped = PlayerInfoResponse;
fn wrap_vars(vars: PlayerInfoVars) -> PlayerInfoVars {
vars
}
fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerInfoResponse> {
let player = response.data?.player?;
Some(PlayerInfoResponse {
name: player.gamer_tag?,
prefix: player.prefix.filter(|pr| !pr.is_empty()),
})
}
}