diff --git a/rust/crates/web/src/app.rs b/rust/crates/web/src/app.rs index 040d678..365df3d 100644 --- a/rust/crates/web/src/app.rs +++ b/rust/crates/web/src/app.rs @@ -1,33 +1,29 @@ use std::sync::Arc; -use async_graphql::{EmptySubscription, Schema}; - use crate::{ - handler::graphql::mutation::MutationRoot, - handler::{graphql::query::QueryRoot, HasGraphQLSchema}, + handler::{graphql::GraphQLSchema, HasGraphQLSchema}, infra::store::InMemoryStore, use_case::{HasStore, Store}, }; #[derive(Clone)] pub struct App { - schema: Schema, + graphql_schema: GraphQLSchema, store: Arc, } impl App { pub fn example() -> Self { - let schema = Schema::new(QueryRoot, MutationRoot, EmptySubscription); Self { - schema, + graphql_schema: GraphQLSchema::new(), store: Arc::new(InMemoryStore::example()), } } } impl HasGraphQLSchema for App { - fn schema(&self) -> &Schema { - &self.schema + fn graphql_schema(&self) -> &GraphQLSchema { + &self.graphql_schema } } diff --git a/rust/crates/web/src/handler/graphql.rs b/rust/crates/web/src/handler/graphql.rs index 95f1c27..567f150 100644 --- a/rust/crates/web/src/handler/graphql.rs +++ b/rust/crates/web/src/handler/graphql.rs @@ -1,5 +1,5 @@ -pub mod mutation; -pub mod query; +mod mutation; +mod query; use std::sync::Arc; @@ -18,15 +18,19 @@ use hyper::StatusCode; use crate::use_case::{HasStore, Store}; +use self::{mutation::MutationRoot, query::QueryRoot}; + +#[derive(Clone)] +pub struct GraphQLSchema(Schema); + +impl GraphQLSchema { + pub fn new() -> Self { + Self(Schema::new(QueryRoot, MutationRoot, EmptySubscription)) + } +} + pub trait HasGraphQLSchema { - // TODO: query, mutation, subscription - fn schema( - &self, - ) -> &Schema< - crate::handler::graphql::query::QueryRoot, - crate::handler::graphql::mutation::MutationRoot, - EmptySubscription, - >; + fn graphql_schema(&self) -> &GraphQLSchema; } async fn handler( @@ -34,7 +38,7 @@ async fn handler( header_map: HeaderMap, request: GraphQLRequest, ) -> Result { - let schema = state.schema(); + let schema = state.graphql_schema(); let store = state.store(); let request = request.into_inner().data(Data { bearer: match header_map.get(axum::http::header::AUTHORIZATION) { @@ -45,7 +49,7 @@ async fn handler( }, store, }); - Ok(GraphQLResponse::from(schema.execute(request).await)) + Ok(GraphQLResponse::from(schema.0.execute(request).await)) } async fn graphiql() -> impl IntoResponse {