Merge pull request 'getting warp to work' (#9) from start-the-warp-engine into main
Reviewed-on: #9
This commit is contained in:
commit
6da1602759
@ -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 {}
|
||||||
|
@ -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
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