forked from projectmoon/tenebrous-dicebot
Add schema generating binary to API server, so we can then proceed with the UI client graphql calls.
This commit is contained in:
parent
6eca450346
commit
a1a37d418a
|
@ -1,5 +1,20 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.15.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a2e47a1fbe209ee101dd6d61285226744c6c8d3c21c8dc878ba6cb9f467f3a"
|
||||
dependencies = [
|
||||
"gimli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aead"
|
||||
version = "0.3.2"
|
||||
|
@ -218,6 +233,21 @@ dependencies = [
|
|||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7815ea54e4d821e791162e078acbebfd6d8c8939cd559c9335dceb1c8ca7282"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"cc",
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "barrel"
|
||||
version = "0.6.5"
|
||||
|
@ -685,6 +715,12 @@ version = "1.0.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
|
||||
|
||||
[[package]]
|
||||
name = "doc-comment"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||
|
||||
[[package]]
|
||||
name = "dotenv"
|
||||
version = "0.15.0"
|
||||
|
@ -709,6 +745,28 @@ dependencies = [
|
|||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "failure"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"failure_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "failure_derive"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fallible-iterator"
|
||||
version = "0.2.0"
|
||||
|
@ -807,6 +865,12 @@ dependencies = [
|
|||
"new_debug_unreachable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.1.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678"
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.3.15"
|
||||
|
@ -872,7 +936,7 @@ version = "0.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50c4e684ddb2d8a4db5ca8a02b35156da129674ba4412b6f528698d58c594954"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -997,6 +1061,12 @@ dependencies = [
|
|||
"polyval",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e4075386626662786ddb0ec9081e7c7eeb1ba31951f447ca780ef9f5d568189"
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.0"
|
||||
|
@ -1059,6 +1129,25 @@ dependencies = [
|
|||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphql-introspection-query"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "610aac641dbd2a457ad4cef34aa2827dae3f035fd214cb38c2d62d8543f3973f"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphql-parser"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5613c31f18676f164112732202124f373bb2103ff017b3b85ca954ea6a66ada"
|
||||
dependencies = [
|
||||
"combine 3.8.1",
|
||||
"failure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphql-parser"
|
||||
version = "0.3.0"
|
||||
|
@ -1069,6 +1158,64 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphql_client"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0bb4f09181e4f80018d01c612125b07e0156f3753bfac37055fe2a25e031ca8"
|
||||
dependencies = [
|
||||
"doc-comment",
|
||||
"failure",
|
||||
"futures 0.1.31",
|
||||
"graphql_query_derive",
|
||||
"js-sys",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures 0.3.27",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphql_client_codegen"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e304c223c809b3bff4614018f8e6d9edb176b31d64ed9ea48b6ae8b1a03abb9"
|
||||
dependencies = [
|
||||
"failure",
|
||||
"graphql-introspection-query",
|
||||
"graphql-parser 0.2.3",
|
||||
"heck",
|
||||
"lazy_static",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphql_client_web"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36901b00f3608f510a091b70848869e1ff1f9b44970b0b882ee62502fca431f0"
|
||||
dependencies = [
|
||||
"graphql_client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphql_query_derive"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1f6b14d5ce549227aa9e649cd9d36d008b91021275a8e0a67d71cef815adc2f"
|
||||
dependencies = [
|
||||
"failure",
|
||||
"graphql_client_codegen",
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "grpc-web-client"
|
||||
version = "0.1.2"
|
||||
|
@ -1078,7 +1225,7 @@ dependencies = [
|
|||
"base64",
|
||||
"byteorder",
|
||||
"bytes",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"getrandom 0.2.3",
|
||||
"http",
|
||||
"http-body",
|
||||
|
@ -1088,7 +1235,7 @@ dependencies = [
|
|||
"prost",
|
||||
"tonic",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-futures 0.4.24",
|
||||
"wasm-streams",
|
||||
"web-sys",
|
||||
]
|
||||
|
@ -1367,9 +1514,9 @@ dependencies = [
|
|||
"bson",
|
||||
"chrono",
|
||||
"fnv",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"futures-enum",
|
||||
"graphql-parser",
|
||||
"graphql-parser 0.3.0",
|
||||
"indexmap",
|
||||
"juniper_codegen",
|
||||
"serde",
|
||||
|
@ -1395,7 +1542,7 @@ name = "juniper_rocket_async"
|
|||
version = "0.5.1"
|
||||
source = "git+https://github.com/graphql-rust/juniper?branch=master#92ad8b46ff4d34cf10925f0a86b56950a354d2ec"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"juniper",
|
||||
"rocket",
|
||||
"serde_json",
|
||||
|
@ -1544,7 +1691,7 @@ dependencies = [
|
|||
"backoff",
|
||||
"bytes",
|
||||
"dashmap",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"futures-timer",
|
||||
"http",
|
||||
"matrix-sdk-base",
|
||||
|
@ -1567,7 +1714,7 @@ source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#0df782
|
|||
dependencies = [
|
||||
"chacha20poly1305",
|
||||
"dashmap",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"hmac",
|
||||
"lru",
|
||||
"matrix-sdk-common",
|
||||
|
@ -1590,14 +1737,14 @@ version = "0.2.0"
|
|||
source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#0df782e93ee2d9d9c338775adbe2cf1b35048740"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"futures-locks",
|
||||
"instant",
|
||||
"ruma",
|
||||
"serde",
|
||||
"tokio",
|
||||
"uuid",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-futures 0.4.24",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1611,7 +1758,7 @@ dependencies = [
|
|||
"base64",
|
||||
"byteorder",
|
||||
"dashmap",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"getrandom 0.2.3",
|
||||
"hmac",
|
||||
"matrix-sdk-common",
|
||||
|
@ -1647,6 +1794,16 @@ version = "0.3.16"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
|
||||
dependencies = [
|
||||
"adler",
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.7.11"
|
||||
|
@ -1782,6 +1939,15 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.25.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8bc1d42047cf336f0f939c99e97183cf31551bf0f2865a2ec9c8d91fd4ffb5e"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "olm-rs"
|
||||
version = "1.0.1"
|
||||
|
@ -2425,7 +2591,7 @@ dependencies = [
|
|||
"tokio-native-tls",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-futures 0.4.24",
|
||||
"web-sys",
|
||||
"winreg",
|
||||
]
|
||||
|
@ -2458,7 +2624,7 @@ dependencies = [
|
|||
"bytes",
|
||||
"either",
|
||||
"figment",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"indexmap",
|
||||
"log",
|
||||
"memchr",
|
||||
|
@ -2752,6 +2918,12 @@ dependencies = [
|
|||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "410f7acf3cb3a44527c5d9546bad4bf4e6c460915d5f9f2fc524498bfe8f70ce"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
|
@ -3066,7 +3238,7 @@ checksum = "01caee2b3935b4efe152f3262afbe51546ce3b1fc27ad61014e1b3cf5f55366e"
|
|||
dependencies = [
|
||||
"dotenv",
|
||||
"either",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"heck",
|
||||
"hex",
|
||||
"once_cell",
|
||||
|
@ -3301,7 +3473,7 @@ dependencies = [
|
|||
"combine 4.5.2",
|
||||
"dirs",
|
||||
"fuse-rust",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"html2text",
|
||||
"indoc",
|
||||
"itertools 0.10.0",
|
||||
|
@ -3340,10 +3512,12 @@ dependencies = [
|
|||
name = "tenebrous-web-ui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"graphql_client",
|
||||
"graphql_client_web",
|
||||
"grpc-web-client",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-futures 0.4.24",
|
||||
"web-sys",
|
||||
"yew",
|
||||
"yew-router",
|
||||
|
@ -3903,6 +4077,19 @@ dependencies = [
|
|||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.3.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"futures 0.1.31",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.24"
|
||||
|
@ -3950,10 +4137,10 @@ version = "0.1.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4f8387cd5b13b87d140234b5be9ab91e9324184fa5170b2778bc4bd1390683d"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-futures 0.4.24",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
|
@ -4069,7 +4256,7 @@ dependencies = [
|
|||
"cfg-if 0.1.10",
|
||||
"cfg-match",
|
||||
"console_error_panic_hook",
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"gloo",
|
||||
"http",
|
||||
"indexmap",
|
||||
|
@ -4083,7 +4270,7 @@ dependencies = [
|
|||
"slab",
|
||||
"thiserror",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-futures 0.4.24",
|
||||
"web-sys",
|
||||
"yew-macro",
|
||||
]
|
||||
|
@ -4160,10 +4347,10 @@ version = "0.3.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "003f4f533ee696c1f69d753db2c66096dec5700a93bd0bc801ab5891fec041c6"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"futures 0.3.15",
|
||||
"log",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-futures 0.4.24",
|
||||
"yew",
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
use tenebrous_api::schema;
|
||||
fn main() {
|
||||
println!("{}", schema::schema().as_schema_language());
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
pub mod schema;
|
|
@ -1,94 +1,8 @@
|
|||
use juniper::{
|
||||
graphql_object, EmptyMutation, EmptySubscription, FieldResult, GraphQLInputObject,
|
||||
GraphQLObject, RootNode,
|
||||
};
|
||||
use rocket::{response::content, Rocket, State};
|
||||
use std::env;
|
||||
use tenebrous_rpc::protos::dicebot::dicebot_client::DicebotClient;
|
||||
use tenebrous_rpc::protos::dicebot::GetVariableRequest;
|
||||
use tonic::{transport::Channel as TonicChannel, Request as TonicRequest};
|
||||
use tenebrous_api::schema::{self, Context, Schema};
|
||||
use tracing_subscriber::filter::EnvFilter;
|
||||
|
||||
//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,
|
||||
}
|
||||
|
||||
//graphql shit
|
||||
#[derive(Clone)]
|
||||
struct Context {
|
||||
dicebot_client: DicebotClient<TonicChannel>,
|
||||
}
|
||||
|
||||
// To make our context usable by Juniper, we have to implement a marker trait.
|
||||
impl juniper::Context for Context {}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Query;
|
||||
|
||||
#[graphql_object(
|
||||
// Here we specify the context type for the object.
|
||||
// We need to do this in every type that
|
||||
// needs access to the context.
|
||||
context = Context,
|
||||
)]
|
||||
impl Query {
|
||||
fn apiVersion() -> &str {
|
||||
"1.0"
|
||||
}
|
||||
|
||||
async fn variable(
|
||||
context: &mut Context,
|
||||
room_id: String,
|
||||
user_id: String,
|
||||
variable: String,
|
||||
) -> FieldResult<UserVariable> {
|
||||
let request = TonicRequest::new(GetVariableRequest {
|
||||
room_id: room_id.clone(),
|
||||
user_id: user_id.clone(),
|
||||
variable_name: variable.clone(),
|
||||
});
|
||||
|
||||
let response = context
|
||||
.dicebot_client
|
||||
.clone()
|
||||
.get_variable(request)
|
||||
.await?
|
||||
.into_inner();
|
||||
|
||||
Ok(UserVariable {
|
||||
user_id: user_id.clone(),
|
||||
room_id: room_id.clone(),
|
||||
variable_name: variable.clone(),
|
||||
value: response.value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type Schema = RootNode<'static, Query, EmptyMutation<Context>, EmptySubscription<Context>>;
|
||||
|
||||
fn schema() -> Schema {
|
||||
Schema::new(
|
||||
Query,
|
||||
EmptyMutation::<Context>::new(),
|
||||
EmptySubscription::<Context>::new(),
|
||||
)
|
||||
}
|
||||
|
||||
//rocket stuff
|
||||
|
||||
#[rocket::get("/")]
|
||||
fn graphiql() -> content::Html<String> {
|
||||
juniper_rocket_async::graphiql_source("/graphql", None)
|
||||
|
@ -114,7 +28,6 @@ async fn post_graphql_handler(
|
|||
|
||||
#[rocket::main]
|
||||
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("hi");
|
||||
let filter = if env::var("RUST_LOG").is_ok() {
|
||||
EnvFilter::from_default_env()
|
||||
} else {
|
||||
|
@ -131,9 +44,11 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
dicebot_client: client,
|
||||
};
|
||||
|
||||
let schema = schema::schema();
|
||||
|
||||
Rocket::build()
|
||||
.manage(context)
|
||||
.manage(schema())
|
||||
.manage(schema)
|
||||
.mount(
|
||||
"/",
|
||||
rocket::routes![graphiql, get_graphql_handler, post_graphql_handler],
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
use juniper::{
|
||||
graphql_object, EmptyMutation, EmptySubscription, FieldResult, GraphQLInputObject,
|
||||
GraphQLObject, RootNode,
|
||||
};
|
||||
use rocket::{response::content, Rocket, State};
|
||||
use std::env;
|
||||
use tenebrous_rpc::protos::dicebot::dicebot_client::DicebotClient;
|
||||
use tenebrous_rpc::protos::dicebot::GetVariableRequest;
|
||||
use tonic::{transport::Channel as TonicChannel, Request as TonicRequest};
|
||||
|
||||
//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,
|
||||
}
|
||||
|
||||
//graphql shit
|
||||
#[derive(Clone)]
|
||||
pub struct Context {
|
||||
pub dicebot_client: DicebotClient<TonicChannel>,
|
||||
}
|
||||
|
||||
// To make our context usable by Juniper, we have to implement a marker trait.
|
||||
impl juniper::Context for Context {}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Query;
|
||||
|
||||
#[graphql_object(
|
||||
// Here we specify the context type for the object.
|
||||
// We need to do this in every type that
|
||||
// needs access to the context.
|
||||
context = Context,
|
||||
)]
|
||||
impl Query {
|
||||
fn apiVersion() -> &str {
|
||||
"1.0"
|
||||
}
|
||||
|
||||
async fn variable(
|
||||
context: &Context,
|
||||
room_id: String,
|
||||
user_id: String,
|
||||
variable: String,
|
||||
) -> FieldResult<UserVariable> {
|
||||
let request = TonicRequest::new(GetVariableRequest {
|
||||
room_id: room_id.clone(),
|
||||
user_id: user_id.clone(),
|
||||
variable_name: variable.clone(),
|
||||
});
|
||||
|
||||
let response = context
|
||||
.dicebot_client
|
||||
.clone()
|
||||
.get_variable(request)
|
||||
.await?
|
||||
.into_inner();
|
||||
|
||||
Ok(UserVariable {
|
||||
user_id: user_id.clone(),
|
||||
room_id: room_id.clone(),
|
||||
variable_name: variable.clone(),
|
||||
value: response.value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub type Schema = RootNode<'static, Query, EmptyMutation<Context>, EmptySubscription<Context>>;
|
||||
|
||||
pub fn schema() -> Schema {
|
||||
Schema::new(
|
||||
Query,
|
||||
EmptyMutation::<Context>::new(),
|
||||
EmptySubscription::<Context>::new(),
|
||||
)
|
||||
}
|
|
@ -19,7 +19,8 @@ wasm-bindgen-futures = "0.4"
|
|||
js-sys = "0.3"
|
||||
grpc-web-client = "0.1"
|
||||
web-sys = "0.3"
|
||||
|
||||
graphql_client = "0.9"
|
||||
graphql_client_web = "0.9"
|
||||
# hopefully we can add grpc-web later instead of graphql.
|
||||
# prost = { version = "0.7.0", default-features = false }
|
||||
# tonic = { git = "https://github.com/hyperium/tonic", branch = "master", default-features = false, features = ["codegen", "prost"] }
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
// #[derive(GraphQLQuery)]
|
||||
// #[graphql(
|
||||
// schema_path = "schema.json",
|
||||
// query_path = "examples/puppy_smiles.graphql",
|
||||
// response_derives = "Debug"
|
||||
// )]
|
||||
// struct PuppySmiles;
|
|
@ -3,6 +3,7 @@ use wasm_bindgen::prelude::*;
|
|||
use yew::prelude::*;
|
||||
use yew_router::{components::RouterAnchor, prelude::*};
|
||||
|
||||
pub mod graphql;
|
||||
pub mod grpc;
|
||||
pub mod rooms;
|
||||
|
||||
|
|
Loading…
Reference in New Issue