From abd9f947abed9db6ca1b4e9f644af38e49a7cafd Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sat, 2 Sep 2023 19:48:47 -0400 Subject: [PATCH] Hide implementation details of query --- cli/src/queries.rs | 42 ++++++++++++++-------------- cli/src/queries/tournament_sets.rs | 45 +++++++++++++++--------------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/cli/src/queries.rs b/cli/src/queries.rs index 20e4c7f..1b52402 100644 --- a/cli/src/queries.rs +++ b/cli/src/queries.rs @@ -9,27 +9,6 @@ pub use tournament_sets::*; use schema::schema; -// Types - -// HACK: Unfortunately, start.gg seems to use integers for its ID type, whereas -// cynic always assumes that IDs are strings. To get around that, we define new -// scalar types that deserialize to u64. - -#[derive(cynic::Scalar, Debug, Copy, Clone)] -#[cynic(graphql_type = "ID")] -pub struct VideogameId(pub u64); - -#[derive(cynic::Scalar, Debug, Copy, Clone)] -#[cynic(graphql_type = "ID")] -pub struct EntrantId(pub u64); - -#[derive(cynic::Scalar, Debug, Copy, Clone)] -#[cynic(graphql_type = "ID")] -pub struct PlayerId(pub u64); - -#[derive(cynic::Scalar, Debug, Clone)] -pub struct Timestamp(pub u64); - // Auth key pub fn get_auth_key(config_dir: &Path) -> Option { @@ -54,6 +33,27 @@ pub fn get_auth_key(config_dir: &Path) -> Option { } } +// Types + +// HACK: Unfortunately, start.gg seems to use integers for its ID type, whereas +// cynic always assumes that IDs are strings. To get around that, we define new +// scalar types that deserialize to u64. + +#[derive(cynic::Scalar, Debug, Copy, Clone)] +#[cynic(graphql_type = "ID")] +pub struct VideogameId(pub u64); + +#[derive(cynic::Scalar, Debug, Copy, Clone)] +#[cynic(graphql_type = "ID")] +pub struct EntrantId(pub u64); + +#[derive(cynic::Scalar, Debug, Copy, Clone)] +#[cynic(graphql_type = "ID")] +pub struct PlayerId(pub u64); + +#[derive(cynic::Scalar, Debug, Clone)] +pub struct Timestamp(pub u64); + // Query machinery pub trait QueryUnwrap: 'static + QueryBuilder { diff --git a/cli/src/queries/tournament_sets.rs b/cli/src/queries/tournament_sets.rs index 5de16b5..4f1d468 100644 --- a/cli/src/queries/tournament_sets.rs +++ b/cli/src/queries/tournament_sets.rs @@ -8,6 +8,7 @@ use schema::schema; pub struct TournamentSetsVars<'a> { // HACK: This should really be an optional variable, but there seems to be a // server-side bug that completely breaks everything when this isn't passed. + // We can use a dummy value of 1 when we don't want to filter by time. pub last_query: Timestamp, pub game_id: VideogameId, @@ -31,65 +32,65 @@ pub struct TournamentSets { countryCode: $country, addrState: $state }})] - pub tournaments: Option, + tournaments: Option, } #[derive(cynic::QueryFragment, Debug)] #[cynic(variables = "TournamentSetsVars")] -pub struct TournamentConnection { +struct TournamentConnection { #[cynic(flatten)] - pub nodes: Vec, + nodes: Vec, } #[derive(cynic::QueryFragment, Debug)] #[cynic(variables = "TournamentSetsVars")] -pub struct Tournament { - pub name: Option, +struct Tournament { + name: Option, #[arguments(limit: 99999, filter: { videogameId: [$game_id] })] #[cynic(flatten)] - pub events: Vec, + events: Vec, } #[derive(cynic::QueryFragment, Debug)] -pub struct Event { +struct Event { #[arguments(page: 1, perPage: 999)] - pub sets: Option, + sets: Option, } #[derive(cynic::QueryFragment, Debug)] -pub struct SetConnection { +struct SetConnection { #[cynic(flatten)] - pub nodes: Vec, + nodes: Vec, } #[derive(cynic::QueryFragment, Debug)] -pub struct Set { +struct Set { #[arguments(includeByes: true)] #[cynic(flatten)] - pub slots: Vec, - pub winner_id: Option, + slots: Vec, + winner_id: Option, } #[derive(cynic::QueryFragment, Debug)] -pub struct SetSlot { - pub entrant: Option, +struct SetSlot { + entrant: Option, } #[derive(cynic::QueryFragment, Debug)] -pub struct Entrant { - pub id: Option, +struct Entrant { + id: Option, #[cynic(flatten)] - pub participants: Vec, + participants: Vec, } #[derive(cynic::QueryFragment, Debug)] -pub struct Participant { - pub player: Option, +struct Participant { + player: Option, } #[derive(cynic::QueryFragment, Debug)] -pub struct Player { - pub id: Option, +struct Player { + id: Option, } // Unwrap