From 8522306298255f234a84c84787751ab02b21e6e5 Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 26 Sep 2021 14:59:56 +0000 Subject: [PATCH] getting warp to work Co-authored-by: Elias Schriefer --- src/graphql.rs | 2 +- src/main.rs | 6 ++++++ src/net.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/net.rs diff --git a/src/graphql.rs b/src/graphql.rs index a5ea9cf..eb64727 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -96,7 +96,7 @@ where #[derive(Clone, Debug)] pub struct Context { #[cfg(feature = "sqlite")] - db: SqlitePool, + pub db: SqlitePool, } impl juniper::Context for Context {} diff --git a/src/main.rs b/src/main.rs index 06cab5b..129a95f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,8 +8,10 @@ use crate::{ config::Config, }; + mod cli; mod config; +mod net; #[cfg(feature = "sqlite")] mod sqlite; mod graphql; @@ -40,5 +42,9 @@ async fn main() -> Result<(), Box> { #[cfg(feature = "sqlite")] sqlite::load_template(&sqlite_connection).await?; + net::web(sqlite_connection).await; + Ok(()) + + } \ No newline at end of file diff --git a/src/net.rs b/src/net.rs new file mode 100644 index 0000000..2a4c7be --- /dev/null +++ b/src/net.rs @@ -0,0 +1,26 @@ +use sqlx::SqlitePool; +use warp::{ + Filter, +}; + +use crate::graphql::{ + Context, + schema, +}; + + +pub async fn web(db: SqlitePool){ + + std::env::set_var("RUST_LOG", "warp_async"); + let state = warp::any().map(move || Context { db: db.clone() }); + let graphql_filter = juniper_warp::make_graphql_filter(schema(), state.boxed()); + + warp::serve( + warp::get() + .and(warp::path("graphiql")) + .and(juniper_warp::graphiql_filter("/graphql", None)) + .or(warp::path("graphql").and(graphql_filter)), + ) + .run(([127, 0, 0, 1], 8080)) + .await; +} \ No newline at end of file -- 2.43.0