diff --git a/Cargo.lock b/Cargo.lock index 434417a..bcdf486 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,21 @@ dependencies = [ "tracing", ] +[[package]] +name = "actix-cors" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0346d8c1f762b41b458ed3145eea914966bb9ad20b9be0d6d463b20d45586370" +dependencies = [ + "actix-utils", + "actix-web", + "derive_more 0.99.19", + "futures-util", + "log", + "once_cell", + "smallvec", +] + [[package]] name = "actix-http" version = "3.10.0" @@ -34,7 +49,7 @@ dependencies = [ "brotli", "bytes", "bytestring", - "derive_more", + "derive_more 2.0.1", "encoding_rs", "flate2", "foldhash", @@ -149,7 +164,7 @@ dependencies = [ "bytestring", "cfg-if", "cookie", - "derive_more", + "derive_more 2.0.1", "encoding_rs", "foldhash", "futures-core", @@ -224,6 +239,29 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "async-trait" +version = "0.1.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "auto_enums" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c170965892137a3a9aeb000b4524aa3cc022a310e709d848b6e1cdce4ab4781" +dependencies = [ + "derive_utils", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.4.0" @@ -319,6 +357,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "cookie" version = "0.16.2" @@ -367,6 +411,19 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_more" +version = "0.99.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3da29a38df43d6f156149c9b43ded5e018ddff2a855cf2cfd62e8cd7d079c69f" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + [[package]] name = "derive_more" version = "2.0.1" @@ -388,6 +445,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "derive_utils" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccfae181bab5ab6c5478b2ccb69e4c68a02f8c3ec72f6616bfec9dbc599d2ee0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "digest" version = "0.10.7" @@ -470,12 +538,42 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + [[package]] name = "futures-core" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + [[package]] name = "futures-sink" version = "0.3.31" @@ -495,9 +593,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-core", + "futures-sink", "futures-task", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -729,6 +829,7 @@ checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" dependencies = [ "equivalent", "hashbrown", + "serde", ] [[package]] @@ -746,6 +847,35 @@ dependencies = [ "libc", ] +[[package]] +name = "juniper" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "943306315b1a7a03d27af9dfb0c288d9f4da8830c17df4bceb7d50a47da0982c" +dependencies = [ + "async-trait", + "auto_enums", + "fnv", + "futures", + "indexmap", + "juniper_codegen", + "serde", + "smartstring", + "static_assertions", +] + +[[package]] +name = "juniper_codegen" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760dbe46660494d469023d661e8d268f413b2cb68c999975dcc237407096a693" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "url", +] + [[package]] name = "language-tags" version = "0.3.2" @@ -807,8 +937,10 @@ checksum = "baee0bbc17ce759db233beb01648088061bf678383130602a298e6998eedb2d8" name = "matchmaker" version = "0.1.0" dependencies = [ + "actix-cors", "actix-web", "fern", + "juniper", "log", "macaddr", "rand 0.9.0", @@ -1152,6 +1284,15 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "ryu" version = "1.0.20" @@ -1164,6 +1305,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "semver" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" + [[package]] name = "serde" version = "1.0.219" @@ -1249,6 +1396,17 @@ version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" +[[package]] +name = "smartstring" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" +dependencies = [ + "autocfg", + "static_assertions", + "version_check", +] + [[package]] name = "socket2" version = "0.5.8" @@ -1265,6 +1423,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "stopwatch" version = "0.0.7" diff --git a/Cargo.toml b/Cargo.toml index bd128e2..90bd750 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,10 @@ license = "MIT License" macaddr = "1.0.1" log = "0.4" actix-web = "4" +actix-cors = "0.6.4" # Used by server runtime fern = { optional = true, version = "0.7" } - +juniper = "0.16.1" [dev-dependencies] stopwatch = "0.0.7" diff --git a/docs/WEBAPI_V1.md b/docs/WEBAPI_V1.md index e76f415..01a0492 100644 --- a/docs/WEBAPI_V1.md +++ b/docs/WEBAPI_V1.md @@ -1,49 +1,3 @@ # Web API Documentation - Draft -## /api/info - -### GET - -```json -{ - "supportedVersions": [ - "" - ], - "partitions": [ - "us", - "uk" - // ... - ], - "heartbeatTimeoutDuration": 7 -} -``` - -## /api/query - -### POST - -```json -{ - // if this is unspecified/null, infer a default partition - "partition": "us", - "" - // Validated against a server-side maximum and minimum - "count": 7, - // Validated to prevent out-of-bounds issues. - // This allows reading a slice of the instances, - // allowing pagination. - "offset": 0 -} -``` - -## /api/connect - - - -## /api/heartbeat - -```json -{ - "token": -} -``` \ No newline at end of file +# GraphQL diff --git a/src/lib.rs b/src/lib.rs index 2515f9b..c7acde9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub mod server; +pub mod web; pub enum MatchmakerError { AlreadyExists, diff --git a/src/web/mod.rs b/src/web/mod.rs new file mode 100644 index 0000000..8b4ddc8 --- /dev/null +++ b/src/web/mod.rs @@ -0,0 +1 @@ +pub mod routes; \ No newline at end of file diff --git a/src/web/routes.rs b/src/web/routes.rs new file mode 100644 index 0000000..d303e74 --- /dev/null +++ b/src/web/routes.rs @@ -0,0 +1,20 @@ +use actix_web::{ + get, web, App, HttpServer, Responder, middleware, + HttpResponse, route +}; +use actix_cors::Cors; +use actix_web_lab::respond::Html; +use juniper::http::{graphiql::graphiql_source, GraphQLRequest}; + +/// Playground +#[get("/graphiql")] +async fn graphql_playground() -> impl Responder { + Html(graphiql_source("/graphql", None)) +} + +/// Endpoint +#[route("/graphql", method = "GET", method = "POST")] +async fn graphql(st: web::Data, data: web::Json) -> impl Responder { + let user = data.execute(&st, &()).await; + HttpResponse::Ok().json(user) +} \ No newline at end of file