From 82656bd849103cb7f8a2351e1b3efff95e6d0320 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Sat, 5 Jun 2021 14:57:44 +0000 Subject: [PATCH] Implement get variable --- api/src/main.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/api/src/main.rs b/api/src/main.rs index 9633d87..fe5f61d 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -1,6 +1,6 @@ use juniper::{ - graphql_object, EmptyMutation, EmptySubscription, FieldError, FieldResult, GraphQLObject, - RootNode, + graphql_object, EmptyMutation, EmptySubscription, FieldError, FieldResult, GraphQLInputObject, + GraphQLObject, RootNode, }; use once_cell::sync::OnceCell; use rocket::{response::content, Rocket, State}; @@ -30,10 +30,18 @@ async fn create_client( } //api stuff +#[derive(GraphQLInputObject)] +struct UserVariableArgument { + room_id: String, + user_id: String, + variable_name: String, +} + #[derive(GraphQLObject)] #[graphql(description = "User variable in a room.")] struct UserVariable { room_id: String, + user_id: String, variable_name: String, value: i32, } @@ -81,6 +89,7 @@ impl Query { .into_inner(); Ok(UserVariable { + user_id: user_id.clone(), room_id: room_id.clone(), variable_name: variable.clone(), value: response.value, @@ -106,21 +115,21 @@ fn graphiql() -> content::Html { } #[rocket::get("/graphql?")] -fn get_graphql_handler( +async fn get_graphql_handler( context: &State, request: juniper_rocket_async::GraphQLRequest, schema: &State, ) -> juniper_rocket_async::GraphQLResponse { - request.execute_sync(&*schema, &*context) + request.execute(&*schema, &*context).await } #[rocket::post("/graphql", data = "")] -fn post_graphql_handler( +async fn post_graphql_handler( context: &State, request: juniper_rocket_async::GraphQLRequest, schema: &State, ) -> juniper_rocket_async::GraphQLResponse { - request.execute_sync(&*schema, &*context) + request.execute(&*schema, &*context).await } #[rocket::main]