diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-08-21 11:59:50 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2024-08-21 12:04:28 +0200 |
commit | 185ba5270aaf94de9b91e4455be27db5198ec21e (patch) | |
tree | fc8d71e7ac6fd6b5b5aa8cc3fbf3c511d2b51342 | |
parent | c2b09dbb88591d9695c1cd2227c5d559b4a8e775 (diff) |
Reformat graphql mod
-rw-r--r-- | src/graphql/mod.rs | 2 | ||||
-rw-r--r-- | src/graphql/query.rs (renamed from src/graphql.rs) | 14 | ||||
-rw-r--r-- | src/graphql/routes.rs | 11 | ||||
-rw-r--r-- | src/main.rs | 4 |
4 files changed, 16 insertions, 15 deletions
diff --git a/src/graphql/mod.rs b/src/graphql/mod.rs new file mode 100644 index 0000000..305f0d3 --- /dev/null +++ b/src/graphql/mod.rs @@ -0,0 +1,2 @@ +pub mod query; +pub mod routes; diff --git a/src/graphql.rs b/src/graphql/query.rs index 2843156..683885e 100644 --- a/src/graphql.rs +++ b/src/graphql/query.rs @@ -1,9 +1,4 @@ -use std::sync::Arc; - -use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema}; -use async_graphql_axum::{GraphQLRequest, GraphQLResponse}; - -// use crate::state::AppState; +use async_graphql::{Context, Object}; pub struct Query; @@ -39,10 +34,3 @@ impl Query { } } } - -pub async fn graphql_handler( - schema: Arc<Schema<Query, EmptyMutation, EmptySubscription>>, - req: GraphQLRequest, -) -> GraphQLResponse { - schema.execute(req.into_inner()).await.into() -} diff --git a/src/graphql/routes.rs b/src/graphql/routes.rs new file mode 100644 index 0000000..2380760 --- /dev/null +++ b/src/graphql/routes.rs @@ -0,0 +1,11 @@ +use crate::graphql::query::*; +use async_graphql::{EmptyMutation, EmptySubscription, Schema}; +use async_graphql_axum::{GraphQLRequest, GraphQLResponse}; +use std::sync::Arc; + +pub async fn graphql_handler( + schema: Arc<Schema<Query, EmptyMutation, EmptySubscription>>, + req: GraphQLRequest, +) -> GraphQLResponse { + schema.execute(req.into_inner()).await.into() +} diff --git a/src/main.rs b/src/main.rs index 7ef7ee6..e87a7c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,13 +30,13 @@ async fn create_app() -> Router { client: Arc::new(dbclient), }; - let schema = Schema::build(graphql::Query, EmptyMutation, EmptySubscription) + let schema = Schema::build(graphql::query::Query, EmptyMutation, EmptySubscription) .data(state.clone()) .finish(); Router::new() .route( "/graphql", - post(move |req| graphql::graphql_handler(schema.clone().into(), req)), + post(move |req| graphql::routes::graphql_handler(schema.clone().into(), req)), ) .fallback(crate::routes::page_404) // Mark the `Authorization` request header as sensitive so it doesn't |