add allWorlds query root
This commit is contained in:
parent
4d9257e77d
commit
27e17fe2ec
1 changed files with 38 additions and 9 deletions
|
@ -6,6 +6,44 @@ use rocket::response::content::RawHtml;
|
||||||
|
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
pub struct Query;
|
||||||
|
|
||||||
|
#[graphql_object(context = Context)]
|
||||||
|
impl Query {
|
||||||
|
fn world(id: ID) -> FieldResult<Option<World>> {
|
||||||
|
Ok(Some(World { id }))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn allWorlds() -> FieldResult<Vec<World>> {
|
||||||
|
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 {
|
pub struct Context {
|
||||||
con: RedisPool,
|
con: RedisPool,
|
||||||
}
|
}
|
||||||
|
@ -40,15 +78,6 @@ pub async fn get_graphql(
|
||||||
query.execute(&*schema, &Context { con: con.clone() }).await
|
query.execute(&*schema, &Context { con: con.clone() }).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Query;
|
|
||||||
|
|
||||||
#[graphql_object(context = Context)]
|
|
||||||
impl Query {
|
|
||||||
fn world(id: ID) -> FieldResult<Option<World>> {
|
|
||||||
Ok(Some(World { id }))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type Schema = juniper::RootNode<
|
pub type Schema = juniper::RootNode<
|
||||||
'static,
|
'static,
|
||||||
Query,
|
Query,
|
||||||
|
|
Loading…
Add table
Reference in a new issue