getting warp to work

Co-authored-by: Elias Schriefer
This commit is contained in:
Erik Foris 2021-09-26 14:59:56 +00:00
parent d9531dc789
commit 8522306298
3 changed files with 33 additions and 1 deletions

View File

@ -96,7 +96,7 @@ where
#[derive(Clone, Debug)]
pub struct Context {
#[cfg(feature = "sqlite")]
db: SqlitePool,
pub db: SqlitePool,
}
impl juniper::Context for Context {}

View File

@ -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<dyn Error>> {
#[cfg(feature = "sqlite")]
sqlite::load_template(&sqlite_connection).await?;
net::web(sqlite_connection).await;
Ok(())
}

26
src/net.rs Normal file
View File

@ -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;
}