forked from projectmoon/tenebrous-dicebot
Implement get user variable in web ui client.
This commit is contained in:
parent
a1a37d418a
commit
e002c9e5c9
|
@ -865,12 +865,6 @@ dependencies = [
|
||||||
"new_debug_unreachable",
|
"new_debug_unreachable",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures"
|
|
||||||
version = "0.1.31"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures"
|
name = "futures"
|
||||||
version = "0.3.15"
|
version = "0.3.15"
|
||||||
|
@ -936,7 +930,7 @@ version = "0.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "50c4e684ddb2d8a4db5ca8a02b35156da129674ba4412b6f528698d58c594954"
|
checksum = "50c4e684ddb2d8a4db5ca8a02b35156da129674ba4412b6f528698d58c594954"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1132,8 +1126,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "graphql-introspection-query"
|
name = "graphql-introspection-query"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518"
|
||||||
checksum = "610aac641dbd2a457ad4cef34aa2827dae3f035fd214cb38c2d62d8543f3973f"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
@ -1161,29 +1154,26 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "graphql_client"
|
name = "graphql_client"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518"
|
||||||
checksum = "a0bb4f09181e4f80018d01c612125b07e0156f3753bfac37055fe2a25e031ca8"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"doc-comment",
|
"doc-comment",
|
||||||
"failure",
|
|
||||||
"futures 0.1.31",
|
|
||||||
"graphql_query_derive",
|
"graphql_query_derive",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures 0.3.27",
|
"wasm-bindgen-futures",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "graphql_client_codegen"
|
name = "graphql_client_codegen"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518"
|
||||||
checksum = "8e304c223c809b3bff4614018f8e6d9edb176b31d64ed9ea48b6ae8b1a03abb9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"failure",
|
|
||||||
"graphql-introspection-query",
|
"graphql-introspection-query",
|
||||||
"graphql-parser 0.2.3",
|
"graphql-parser 0.2.3",
|
||||||
"heck",
|
"heck",
|
||||||
|
@ -1193,13 +1183,13 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"syn",
|
"syn",
|
||||||
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "graphql_client_web"
|
name = "graphql_client_web"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518"
|
||||||
checksum = "36901b00f3608f510a091b70848869e1ff1f9b44970b0b882ee62502fca431f0"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"graphql_client",
|
"graphql_client",
|
||||||
]
|
]
|
||||||
|
@ -1207,39 +1197,13 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "graphql_query_derive"
|
name = "graphql_query_derive"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/graphql-rust/graphql-client?branch=master#de2f4aeaa147864b86b7a8abe50f334d7d9f7518"
|
||||||
checksum = "e1f6b14d5ce549227aa9e649cd9d36d008b91021275a8e0a67d71cef815adc2f"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"failure",
|
|
||||||
"graphql_client_codegen",
|
"graphql_client_codegen",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
|
@ -1514,7 +1478,7 @@ dependencies = [
|
||||||
"bson",
|
"bson",
|
||||||
"chrono",
|
"chrono",
|
||||||
"fnv",
|
"fnv",
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"futures-enum",
|
"futures-enum",
|
||||||
"graphql-parser 0.3.0",
|
"graphql-parser 0.3.0",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
|
@ -1542,7 +1506,7 @@ name = "juniper_rocket_async"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
source = "git+https://github.com/graphql-rust/juniper?branch=master#92ad8b46ff4d34cf10925f0a86b56950a354d2ec"
|
source = "git+https://github.com/graphql-rust/juniper?branch=master#92ad8b46ff4d34cf10925f0a86b56950a354d2ec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"juniper",
|
"juniper",
|
||||||
"rocket",
|
"rocket",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -1691,7 +1655,7 @@ dependencies = [
|
||||||
"backoff",
|
"backoff",
|
||||||
"bytes",
|
"bytes",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"futures-timer",
|
"futures-timer",
|
||||||
"http",
|
"http",
|
||||||
"matrix-sdk-base",
|
"matrix-sdk-base",
|
||||||
|
@ -1714,7 +1678,7 @@ source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#0df782
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chacha20poly1305",
|
"chacha20poly1305",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"hmac",
|
"hmac",
|
||||||
"lru",
|
"lru",
|
||||||
"matrix-sdk-common",
|
"matrix-sdk-common",
|
||||||
|
@ -1737,14 +1701,14 @@ version = "0.2.0"
|
||||||
source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#0df782e93ee2d9d9c338775adbe2cf1b35048740"
|
source = "git+https://github.com/matrix-org/matrix-rust-sdk?branch=master#0df782e93ee2d9d9c338775adbe2cf1b35048740"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"futures-locks",
|
"futures-locks",
|
||||||
"instant",
|
"instant",
|
||||||
"ruma",
|
"ruma",
|
||||||
"serde",
|
"serde",
|
||||||
"tokio",
|
"tokio",
|
||||||
"uuid",
|
"uuid",
|
||||||
"wasm-bindgen-futures 0.4.24",
|
"wasm-bindgen-futures",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1758,7 +1722,7 @@ dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"getrandom 0.2.3",
|
"getrandom 0.2.3",
|
||||||
"hmac",
|
"hmac",
|
||||||
"matrix-sdk-common",
|
"matrix-sdk-common",
|
||||||
|
@ -2591,7 +2555,7 @@ dependencies = [
|
||||||
"tokio-native-tls",
|
"tokio-native-tls",
|
||||||
"url",
|
"url",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures 0.4.24",
|
"wasm-bindgen-futures",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"winreg",
|
"winreg",
|
||||||
]
|
]
|
||||||
|
@ -2624,7 +2588,7 @@ dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"either",
|
"either",
|
||||||
"figment",
|
"figment",
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"log",
|
"log",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
@ -3238,7 +3202,7 @@ checksum = "01caee2b3935b4efe152f3262afbe51546ce3b1fc27ad61014e1b3cf5f55366e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"either",
|
"either",
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"heck",
|
"heck",
|
||||||
"hex",
|
"hex",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
@ -3473,7 +3437,7 @@ dependencies = [
|
||||||
"combine 4.5.2",
|
"combine 4.5.2",
|
||||||
"dirs",
|
"dirs",
|
||||||
"fuse-rust",
|
"fuse-rust",
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"html2text",
|
"html2text",
|
||||||
"indoc",
|
"indoc",
|
||||||
"itertools 0.10.0",
|
"itertools 0.10.0",
|
||||||
|
@ -3514,10 +3478,11 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"graphql_client",
|
"graphql_client",
|
||||||
"graphql_client_web",
|
"graphql_client_web",
|
||||||
"grpc-web-client",
|
|
||||||
"js-sys",
|
"js-sys",
|
||||||
|
"serde",
|
||||||
|
"tenebrous-api",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures 0.4.24",
|
"wasm-bindgen-futures",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"yew",
|
"yew",
|
||||||
"yew-router",
|
"yew-router",
|
||||||
|
@ -4077,19 +4042,6 @@ dependencies = [
|
||||||
"wasm-bindgen-shared",
|
"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]]
|
[[package]]
|
||||||
name = "wasm-bindgen-futures"
|
name = "wasm-bindgen-futures"
|
||||||
version = "0.4.24"
|
version = "0.4.24"
|
||||||
|
@ -4131,19 +4083,6 @@ version = "0.2.74"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f"
|
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]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.51"
|
version = "0.3.51"
|
||||||
|
@ -4256,7 +4195,7 @@ dependencies = [
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
"cfg-match",
|
"cfg-match",
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"gloo",
|
"gloo",
|
||||||
"http",
|
"http",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
|
@ -4270,7 +4209,7 @@ dependencies = [
|
||||||
"slab",
|
"slab",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures 0.4.24",
|
"wasm-bindgen-futures",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"yew-macro",
|
"yew-macro",
|
||||||
]
|
]
|
||||||
|
@ -4347,10 +4286,10 @@ version = "0.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "003f4f533ee696c1f69d753db2c66096dec5700a93bd0bc801ab5891fec041c6"
|
checksum = "003f4f533ee696c1f69d753db2c66096dec5700a93bd0bc801ab5891fec041c6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures 0.3.15",
|
"futures",
|
||||||
"log",
|
"log",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures 0.4.24",
|
"wasm-bindgen-futures",
|
||||||
"yew",
|
"yew",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@ edition = "2018"
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
tenebrous-api = { path = "../../api" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
yew = { version = "0.17" }
|
yew = { version = "0.17" }
|
||||||
yewtil = {version = "0.3" }
|
yewtil = {version = "0.3" }
|
||||||
|
@ -17,10 +20,12 @@ yewdux = {version = "^0.6" }
|
||||||
wasm-bindgen = { version = "0.2" }
|
wasm-bindgen = { version = "0.2" }
|
||||||
wasm-bindgen-futures = "0.4"
|
wasm-bindgen-futures = "0.4"
|
||||||
js-sys = "0.3"
|
js-sys = "0.3"
|
||||||
grpc-web-client = "0.1"
|
#grpc-web-client = "0.1"
|
||||||
web-sys = "0.3"
|
web-sys = "0.3"
|
||||||
graphql_client = "0.9"
|
graphql_client = { git = "https://github.com/graphql-rust/graphql-client", branch = "master" }
|
||||||
graphql_client_web = "0.9"
|
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.
|
# hopefully we can add grpc-web later instead of graphql.
|
||||||
# prost = { version = "0.7.0", default-features = false }
|
# prost = { version = "0.7.0", default-features = false }
|
||||||
# tonic = { git = "https://github.com/hyperium/tonic", branch = "master", default-features = false, features = ["codegen", "prost"] }
|
# tonic = { git = "https://github.com/hyperium/tonic", branch = "master", default-features = false, features = ["codegen", "prost"] }
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
use std::fs;
|
||||||
|
use tenebrous_api::schema;
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let schema_doc = schema::schema().as_schema_language();
|
||||||
|
fs::write("schema.graphql", schema_doc)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
query GetUserVariable($roomId: String!, $userId: String!, $variable: String!) {
|
||||||
|
variable(roomId: $roomId, userId: $userId, variable: $variable) {
|
||||||
|
roomId
|
||||||
|
userId
|
||||||
|
value
|
||||||
|
variableName
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -1,7 +1,30 @@
|
||||||
// #[derive(GraphQLQuery)]
|
use graphql_client::web::Client;
|
||||||
// #[graphql(
|
use graphql_client::web::ClientError;
|
||||||
// schema_path = "schema.json",
|
use graphql_client::GraphQLQuery;
|
||||||
// query_path = "examples/puppy_smiles.graphql",
|
|
||||||
// response_derives = "Debug"
|
#[derive(GraphQLQuery)]
|
||||||
// )]
|
#[graphql(
|
||||||
// struct PuppySmiles;
|
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<i64, ClientError> {
|
||||||
|
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<get_user_variable::ResponseData> = response;
|
||||||
|
let value = response.data.map(|d| d.variable.value).unwrap();
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue