2021-10-23 17:39:05 +02:00
|
|
|
use std::net::IpAddr;
|
2021-09-26 16:59:56 +02:00
|
|
|
use sqlx::SqlitePool;
|
2021-10-23 17:39:05 +02:00
|
|
|
use warp::Filter;
|
2021-09-26 16:59:56 +02:00
|
|
|
|
|
|
|
use crate::graphql::{
|
|
|
|
Context,
|
|
|
|
schema,
|
|
|
|
};
|
|
|
|
|
2021-10-23 17:39:05 +02:00
|
|
|
pub async fn web(ip_address: IpAddr, port: u16, db: SqlitePool) {
|
2021-09-26 16:59:56 +02:00
|
|
|
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)),
|
2021-10-23 17:39:05 +02:00
|
|
|
).run((ip_address, port)).await;
|
2021-09-26 16:59:56 +02:00
|
|
|
}
|