getting warp to work #9
@ -96,7 +96,7 @@ where
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Context {
|
||||
#[cfg(feature = "sqlite")]
|
||||
db: SqlitePool,
|
||||
pub db: SqlitePool,
|
||||
}
|
||||
|
||||
impl juniper::Context for Context {}
|
||||
|
@ -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
26
src/net.rs
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user