forked from projectmoon/tenebrous-dicebot
Implement get variable
This commit is contained in:
parent
6dfc9119f7
commit
82656bd849
|
@ -1,6 +1,6 @@
|
||||||
use juniper::{
|
use juniper::{
|
||||||
graphql_object, EmptyMutation, EmptySubscription, FieldError, FieldResult, GraphQLObject,
|
graphql_object, EmptyMutation, EmptySubscription, FieldError, FieldResult, GraphQLInputObject,
|
||||||
RootNode,
|
GraphQLObject, RootNode,
|
||||||
};
|
};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use rocket::{response::content, Rocket, State};
|
use rocket::{response::content, Rocket, State};
|
||||||
|
@ -30,10 +30,18 @@ async fn create_client(
|
||||||
}
|
}
|
||||||
|
|
||||||
//api stuff
|
//api stuff
|
||||||
|
#[derive(GraphQLInputObject)]
|
||||||
|
struct UserVariableArgument {
|
||||||
|
room_id: String,
|
||||||
|
user_id: String,
|
||||||
|
variable_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(GraphQLObject)]
|
#[derive(GraphQLObject)]
|
||||||
#[graphql(description = "User variable in a room.")]
|
#[graphql(description = "User variable in a room.")]
|
||||||
struct UserVariable {
|
struct UserVariable {
|
||||||
room_id: String,
|
room_id: String,
|
||||||
|
user_id: String,
|
||||||
variable_name: String,
|
variable_name: String,
|
||||||
value: i32,
|
value: i32,
|
||||||
}
|
}
|
||||||
|
@ -81,6 +89,7 @@ impl Query {
|
||||||
.into_inner();
|
.into_inner();
|
||||||
|
|
||||||
Ok(UserVariable {
|
Ok(UserVariable {
|
||||||
|
user_id: user_id.clone(),
|
||||||
room_id: room_id.clone(),
|
room_id: room_id.clone(),
|
||||||
variable_name: variable.clone(),
|
variable_name: variable.clone(),
|
||||||
value: response.value,
|
value: response.value,
|
||||||
|
@ -106,21 +115,21 @@ fn graphiql() -> content::Html<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::get("/graphql?<request>")]
|
#[rocket::get("/graphql?<request>")]
|
||||||
fn get_graphql_handler(
|
async fn get_graphql_handler(
|
||||||
context: &State<Context>,
|
context: &State<Context>,
|
||||||
request: juniper_rocket_async::GraphQLRequest,
|
request: juniper_rocket_async::GraphQLRequest,
|
||||||
schema: &State<Schema>,
|
schema: &State<Schema>,
|
||||||
) -> juniper_rocket_async::GraphQLResponse {
|
) -> juniper_rocket_async::GraphQLResponse {
|
||||||
request.execute_sync(&*schema, &*context)
|
request.execute(&*schema, &*context).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::post("/graphql", data = "<request>")]
|
#[rocket::post("/graphql", data = "<request>")]
|
||||||
fn post_graphql_handler(
|
async fn post_graphql_handler(
|
||||||
context: &State<Context>,
|
context: &State<Context>,
|
||||||
request: juniper_rocket_async::GraphQLRequest,
|
request: juniper_rocket_async::GraphQLRequest,
|
||||||
schema: &State<Schema>,
|
schema: &State<Schema>,
|
||||||
) -> juniper_rocket_async::GraphQLResponse {
|
) -> juniper_rocket_async::GraphQLResponse {
|
||||||
request.execute_sync(&*schema, &*context)
|
request.execute(&*schema, &*context).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
|
|
Loading…
Reference in New Issue