From 27e17fe2ec0aace353fc06ee868f7b0987bb8b34 Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Fri, 25 Nov 2022 18:53:03 -0500 Subject: [PATCH] add allWorlds query root --- services/api/src/graphql/mod.rs | 47 ++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/services/api/src/graphql/mod.rs b/services/api/src/graphql/mod.rs index d97c669..eb7cda8 100644 --- a/services/api/src/graphql/mod.rs +++ b/services/api/src/graphql/mod.rs @@ -6,6 +6,44 @@ use rocket::response::content::RawHtml; pub mod types; +pub struct Query; + +#[graphql_object(context = Context)] +impl Query { + fn world(id: ID) -> FieldResult> { + Ok(Some(World { id })) + } + + fn allWorlds() -> FieldResult> { + Ok(vec![ + World { + id: ID::from("1".to_string()), + }, + World { + id: ID::from("10".to_string()), + }, + World { + id: ID::from("13".to_string()), + }, + World { + id: ID::from("17".to_string()), + }, + World { + id: ID::from("19".to_string()), + }, + World { + id: ID::from("40".to_string()), + }, + World { + id: ID::from("1000".to_string()), + }, + World { + id: ID::from("2000".to_string()), + }, + ]) + } +} + pub struct Context { con: RedisPool, } @@ -40,15 +78,6 @@ pub async fn get_graphql( query.execute(&*schema, &Context { con: con.clone() }).await } -pub struct Query; - -#[graphql_object(context = Context)] -impl Query { - fn world(id: ID) -> FieldResult> { - Ok(Some(World { id })) - } -} - pub type Schema = juniper::RootNode< 'static, Query,