Merge pull request 'getting warp to work' (#9) from start-the-warp-engine into main

Reviewed-on: #9
This commit is contained in:
Erik Foris 2021-09-27 12:54:18 +00:00
commit 6da1602759
3 changed files with 33 additions and 1 deletions

View File

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

View File

@ -8,8 +8,10 @@ use crate::{
config::Config, config::Config,
}; };
mod cli; mod cli;
mod config; mod config;
mod net;
#[cfg(feature = "sqlite")] #[cfg(feature = "sqlite")]
mod sqlite; mod sqlite;
mod graphql; mod graphql;
@ -40,5 +42,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
#[cfg(feature = "sqlite")] #[cfg(feature = "sqlite")]
sqlite::load_template(&sqlite_connection).await?; sqlite::load_template(&sqlite_connection).await?;
net::web(sqlite_connection).await;
Ok(()) 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;
}