Write videogame search query
This commit is contained in:
parent
5fdc8cb50e
commit
a1e23b453d
7
cli/build.rs
Normal file
7
cli/build.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fn main() {
|
||||||
|
cynic_codegen::register_schema("startgg")
|
||||||
|
.from_sdl_file("../schema/src/startgg.graphql")
|
||||||
|
.unwrap()
|
||||||
|
.as_default()
|
||||||
|
.unwrap();
|
||||||
|
}
|
|
@ -1,5 +1,9 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
mod queries;
|
||||||
|
use queries::*;
|
||||||
|
|
||||||
|
|
||||||
fn get_auth_key() -> Option<String> {
|
fn get_auth_key() -> Option<String> {
|
||||||
env::var("AUTH_KEY").ok()
|
env::var("AUTH_KEY").ok()
|
||||||
}
|
}
|
||||||
|
|
2
cli/src/queries.rs
Normal file
2
cli/src/queries.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
mod search_games;
|
29
cli/src/queries/search_games.rs
Normal file
29
cli/src/queries/search_games.rs
Normal file
|
@ -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<VideogameConnection>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
|
pub struct VideogameConnection {
|
||||||
|
pub nodes: Option<Vec<Option<Videogame>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
|
pub struct Videogame {
|
||||||
|
pub id: Option<cynic::Id>,
|
||||||
|
pub name: Option<String>,
|
||||||
|
}
|
Loading…
Reference in a new issue