diff --git a/Cargo.lock b/Cargo.lock index 898757c..8fdd2fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -865,12 +865,6 @@ 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" @@ -936,7 +930,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50c4e684ddb2d8a4db5ca8a02b35156da129674ba4412b6f528698d58c594954" dependencies = [ - "futures 0.3.15", + "futures", ] [[package]] @@ -1132,8 +1126,7 @@ dependencies = [ [[package]] name = "graphql-introspection-query" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "610aac641dbd2a457ad4cef34aa2827dae3f035fd214cb38c2d62d8543f3973f" +source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518" dependencies = [ "serde", ] @@ -1161,29 +1154,26 @@ dependencies = [ [[package]] name = "graphql_client" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0bb4f09181e4f80018d01c612125b07e0156f3753bfac37055fe2a25e031ca8" +source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518" dependencies = [ + "anyhow", "doc-comment", - "failure", - "futures 0.1.31", "graphql_query_derive", "js-sys", "log", "serde", "serde_json", + "thiserror", "wasm-bindgen", - "wasm-bindgen-futures 0.3.27", + "wasm-bindgen-futures", "web-sys", ] [[package]] name = "graphql_client_codegen" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e304c223c809b3bff4614018f8e6d9edb176b31d64ed9ea48b6ae8b1a03abb9" +source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518" dependencies = [ - "failure", "graphql-introspection-query", "graphql-parser 0.2.3", "heck", @@ -1193,13 +1183,13 @@ dependencies = [ "serde", "serde_json", "syn", + "thiserror", ] [[package]] name = "graphql_client_web" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36901b00f3608f510a091b70848869e1ff1f9b44970b0b882ee62502fca431f0" +source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518" dependencies = [ "graphql_client", ] @@ -1207,39 +1197,13 @@ dependencies = [ [[package]] name = "graphql_query_derive" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1f6b14d5ce549227aa9e649cd9d36d008b91021275a8e0a67d71cef815adc2f" +source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518" dependencies = [ - "failure", "graphql_client_codegen", "proc-macro2", "syn", ] -[[package]] -name = "grpc-web-client" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52b8f66de5a7a111fcb5bc3ed646f9e6db8dde6bb0ab6c5555e718b4f97fa681" -dependencies = [ - "base64", - "byteorder", - "bytes", - "futures 0.3.15", - "getrandom 0.2.3", - "http", - "http-body", - "httparse", - "hyper", - "js-sys", - "prost", - "tonic", - "wasm-bindgen", - "wasm-bindgen-futures 0.4.24", - "wasm-streams", - "web-sys", -] - [[package]] name = "h2" version = "0.3.3" @@ -1514,7 +1478,7 @@ dependencies = [ "bson", "chrono", "fnv", - "futures 0.3.15", + "futures", "futures-enum", "graphql-parser 0.3.0", "indexmap", @@ -1542,7 +1506,7 @@ name = "juniper_rocket_async" version = "0.5.1" source = "git+https://github.com/graphql-rust/juniper?branch=master#92ad8b46ff4d34cf10925f0a86b56950a354d2ec" dependencies = [ - "futures 0.3.15", + "futures", "juniper", "rocket", "serde_json", @@ -1691,7 +1655,7 @@ dependencies = [ "backoff", "bytes", "dashmap", - "futures 0.3.15", + "futures", "futures-timer", "http", "matrix-sdk-base", @@ -1714,7 +1678,7 @@ source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#0df782 dependencies = [ "chacha20poly1305", "dashmap", - "futures 0.3.15", + "futures", "hmac", "lru", "matrix-sdk-common", @@ -1737,14 +1701,14 @@ version = "0.2.0" source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#0df782e93ee2d9d9c338775adbe2cf1b35048740" dependencies = [ "async-trait", - "futures 0.3.15", + "futures", "futures-locks", "instant", "ruma", "serde", "tokio", "uuid", - "wasm-bindgen-futures 0.4.24", + "wasm-bindgen-futures", ] [[package]] @@ -1758,7 +1722,7 @@ dependencies = [ "base64", "byteorder", "dashmap", - "futures 0.3.15", + "futures", "getrandom 0.2.3", "hmac", "matrix-sdk-common", @@ -2591,7 +2555,7 @@ dependencies = [ "tokio-native-tls", "url", "wasm-bindgen", - "wasm-bindgen-futures 0.4.24", + "wasm-bindgen-futures", "web-sys", "winreg", ] @@ -2624,7 +2588,7 @@ dependencies = [ "bytes", "either", "figment", - "futures 0.3.15", + "futures", "indexmap", "log", "memchr", @@ -3238,7 +3202,7 @@ checksum = "01caee2b3935b4efe152f3262afbe51546ce3b1fc27ad61014e1b3cf5f55366e" dependencies = [ "dotenv", "either", - "futures 0.3.15", + "futures", "heck", "hex", "once_cell", @@ -3473,7 +3437,7 @@ dependencies = [ "combine 4.5.2", "dirs", "fuse-rust", - "futures 0.3.15", + "futures", "html2text", "indoc", "itertools 0.10.0", @@ -3514,10 +3478,11 @@ version = "0.1.0" dependencies = [ "graphql_client", "graphql_client_web", - "grpc-web-client", "js-sys", + "serde", + "tenebrous-api", "wasm-bindgen", - "wasm-bindgen-futures 0.4.24", + "wasm-bindgen-futures", "web-sys", "yew", "yew-router", @@ -4077,19 +4042,6 @@ 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" @@ -4131,19 +4083,6 @@ version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" -[[package]] -name = "wasm-streams" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4f8387cd5b13b87d140234b5be9ab91e9324184fa5170b2778bc4bd1390683d" -dependencies = [ - "futures 0.3.15", - "js-sys", - "wasm-bindgen", - "wasm-bindgen-futures 0.4.24", - "web-sys", -] - [[package]] name = "web-sys" version = "0.3.51" @@ -4256,7 +4195,7 @@ dependencies = [ "cfg-if 0.1.10", "cfg-match", "console_error_panic_hook", - "futures 0.3.15", + "futures", "gloo", "http", "indexmap", @@ -4270,7 +4209,7 @@ dependencies = [ "slab", "thiserror", "wasm-bindgen", - "wasm-bindgen-futures 0.4.24", + "wasm-bindgen-futures", "web-sys", "yew-macro", ] @@ -4347,10 +4286,10 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "003f4f533ee696c1f69d753db2c66096dec5700a93bd0bc801ab5891fec041c6" dependencies = [ - "futures 0.3.15", + "futures", "log", "wasm-bindgen", - "wasm-bindgen-futures 0.4.24", + "wasm-bindgen-futures", "yew", ] diff --git a/web-ui/crate/Cargo.toml b/web-ui/crate/Cargo.toml index ad242c2..54af717 100644 --- a/web-ui/crate/Cargo.toml +++ b/web-ui/crate/Cargo.toml @@ -9,6 +9,9 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] +[build-dependencies] +tenebrous-api = { path = "../../api" } + [dependencies] yew = { version = "0.17" } yewtil = {version = "0.3" } @@ -17,10 +20,12 @@ yewdux = {version = "^0.6" } wasm-bindgen = { version = "0.2" } wasm-bindgen-futures = "0.4" js-sys = "0.3" -grpc-web-client = "0.1" +#grpc-web-client = "0.1" web-sys = "0.3" -graphql_client = "0.9" -graphql_client_web = "0.9" +graphql_client = { git = "https://github.com/graphql-rust/graphql-client", branch = "master" } +graphql_client_web = { git = "https://github.com/graphql-rust/graphql-client", branch = "master" } +serde = { version = "1.0.67", features = ["derive"] } + # 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"] } diff --git a/web-ui/crate/build.rs b/web-ui/crate/build.rs new file mode 100644 index 0000000..76c8dc4 --- /dev/null +++ b/web-ui/crate/build.rs @@ -0,0 +1,7 @@ +use std::fs; +use tenebrous_api::schema; +fn main() -> Result<(), Box> { + let schema_doc = schema::schema().as_schema_language(); + fs::write("schema.graphql", schema_doc)?; + Ok(()) +} diff --git a/web-ui/crate/graphql/queries/get_user_variable.graphql b/web-ui/crate/graphql/queries/get_user_variable.graphql new file mode 100644 index 0000000..4d1fe29 --- /dev/null +++ b/web-ui/crate/graphql/queries/get_user_variable.graphql @@ -0,0 +1,8 @@ +query GetUserVariable($roomId: String!, $userId: String!, $variable: String!) { + variable(roomId: $roomId, userId: $userId, variable: $variable) { + roomId + userId + value + variableName + } +} diff --git a/web-ui/crate/graphql/schema.graphql b/web-ui/crate/graphql/schema.graphql new file mode 100644 index 0000000..8cecd3b --- /dev/null +++ b/web-ui/crate/graphql/schema.graphql @@ -0,0 +1,16 @@ +"User variable in a room." +type UserVariable { + roomId: String! + userId: String! + variableName: String! + value: Int! +} + +type Query { + apiVersion: String! + variable(roomId: String!, userId: String!, variable: String!): UserVariable! +} + +schema { + query: Query +} diff --git a/web-ui/crate/schema.graphql b/web-ui/crate/schema.graphql new file mode 100644 index 0000000..8cecd3b --- /dev/null +++ b/web-ui/crate/schema.graphql @@ -0,0 +1,16 @@ +"User variable in a room." +type UserVariable { + roomId: String! + userId: String! + variableName: String! + value: Int! +} + +type Query { + apiVersion: String! + variable(roomId: String!, userId: String!, variable: String!): UserVariable! +} + +schema { + query: Query +} diff --git a/web-ui/crate/src/graphql.rs b/web-ui/crate/src/graphql.rs index 2caec07..8efcfee 100644 --- a/web-ui/crate/src/graphql.rs +++ b/web-ui/crate/src/graphql.rs @@ -1,7 +1,30 @@ -// #[derive(GraphQLQuery)] -// #[graphql( -// schema_path = "schema.json", -// query_path = "examples/puppy_smiles.graphql", -// response_derives = "Debug" -// )] -// struct PuppySmiles; +use graphql_client::web::Client; +use graphql_client::web::ClientError; +use graphql_client::GraphQLQuery; + +#[derive(GraphQLQuery)] +#[graphql( + schema_path = "graphql/schema.graphql", + query_path = "graphql/queries/get_user_variable.graphql", + response_derives = "Debug" +)] +struct GetUserVariable; + +pub async fn get_user_variable( + room_id: &str, + user_id: &str, + variable_name: &str, +) -> Result { + let client = Client::new("http://localhost:10000/graphql"); + let variables = get_user_variable::Variables { + room_id: room_id.to_owned(), + user_id: user_id.to_owned(), + variable: variable_name.to_owned(), + }; + + //TODO don't unwrap() option. map to err instead. + let response = client.call(GetUserVariable, variables).await?; + let response: graphql_client_web::Response = response; + let value = response.data.map(|d| d.variable.value).unwrap(); + Ok(value) +}