From a1e23b453d5a2ed6d72f1ea892f986ada960238d Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sat, 26 Aug 2023 23:48:13 -0400 Subject: [PATCH] Write videogame search query --- cli/build.rs | 7 +++++++ cli/src/main.rs | 4 ++++ cli/src/queries.rs | 2 ++ cli/src/queries/search_games.rs | 29 +++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 cli/build.rs create mode 100644 cli/src/queries.rs create mode 100644 cli/src/queries/search_games.rs diff --git a/cli/build.rs b/cli/build.rs new file mode 100644 index 0000000..cce8286 --- /dev/null +++ b/cli/build.rs @@ -0,0 +1,7 @@ +fn main() { + cynic_codegen::register_schema("startgg") + .from_sdl_file("../schema/src/startgg.graphql") + .unwrap() + .as_default() + .unwrap(); +} diff --git a/cli/src/main.rs b/cli/src/main.rs index 1aa7aa1..d87dca4 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,5 +1,9 @@ use std::env; +mod queries; +use queries::*; + + fn get_auth_key() -> Option { env::var("AUTH_KEY").ok() } diff --git a/cli/src/queries.rs b/cli/src/queries.rs new file mode 100644 index 0000000..a4f64ec --- /dev/null +++ b/cli/src/queries.rs @@ -0,0 +1,2 @@ + +mod search_games; diff --git a/cli/src/queries/search_games.rs b/cli/src/queries/search_games.rs new file mode 100644 index 0000000..e6d4033 --- /dev/null +++ b/cli/src/queries/search_games.rs @@ -0,0 +1,29 @@ + +use schema::schema; + +// VARIABLES + +#[derive(cynic::QueryVariables)] +pub struct VideogameSearchVars { + name: String +} + +// QUERY + +#[derive(cynic::QueryFragment, Debug)] +#[cynic(graphql_type = "Query", variables = "VideogameSearchVars")] +pub struct VideogameSearch { + #[arguments(query: { filter: { name: $name }, page: 1, perPage: 10 })] + pub videogames: Option, +} + +#[derive(cynic::QueryFragment, Debug)] +pub struct VideogameConnection { + pub nodes: Option>>, +} + +#[derive(cynic::QueryFragment, Debug)] +pub struct Videogame { + pub id: Option, + pub name: Option, +}