add start

This commit is contained in:
2022-10-02 14:15:45 +02:00
parent 351b92e54b
commit 4c66fb1e7a
13 changed files with 293 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
use std::env::{self, current_dir};
mod gqlx;
mod graphql;
mod services;
use axum::{
extract::Extension,
@@ -12,14 +14,15 @@ use axum::{
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
EmptyMutation, EmptySubscription, Request, Response, Schema,
EmptySubscription, Request, Response, Schema,
};
use graphql::CibusSchema;
use services::users_service;
use sqlx::PgPool;
use tower_http::{cors::CorsLayer, trace::TraceLayer};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use crate::graphql::QueryRoot;
use crate::graphql::{MutationRoot, QueryRoot};
async fn graphql_handler(schema: Extension<CibusSchema>, req: Json<Request>) -> Json<Response> {
schema.execute(req.0).await.into()
@@ -39,7 +42,8 @@ async fn main() -> anyhow::Result<()> {
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new(
std::env::var("RUST_LOG").unwrap_or_else(|_| {
"como_bin=debug,tower_http=debug,axum_extra=debug,hyper=info,mio=info".into()
"como_bin=debug,tower_http=debug,axum_extra=debug,hyper=info,mio=info,sqlx=info,async_graphql=debug"
.into()
}),
))
.with(tracing_subscriber::fmt::layer())
@@ -58,7 +62,9 @@ async fn main() -> anyhow::Result<()> {
// Schema
println!("Building schema");
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription).finish();
let schema = Schema::build(QueryRoot, MutationRoot, EmptySubscription)
.data(users_service::UserService::new(pool))
.finish();
// CORS
let cors = vec!["http://localhost:3000".parse().unwrap()];