Write player info query
This commit is contained in:
parent
abd9f947ab
commit
9d5ff8f125
|
@ -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;
|
||||||
|
|
||||||
|
|
49
cli/src/queries/player_info.rs
Normal file
49
cli/src/queries/player_info.rs
Normal 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()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue