reactive_graph_graphql_impl/
graphql_system_impl.rs1use std::sync::Arc;
2
3use async_trait::async_trait;
4use reactive_graph_di::get_shared_component_factory;
5use springtime_di::Component;
6use springtime_di::component_alias;
7use springtime_di::instance_provider::TypedComponentInstanceProvider;
8
9use reactive_graph_graphql_api::GraphQLQueryService;
10use reactive_graph_graphql_api::GraphQLSchemaManager;
11use reactive_graph_graphql_api::GraphQLSystem;
12use reactive_graph_lifecycle::Lifecycle;
13
14#[derive(Component)]
15pub struct GraphQLSystemImpl {
16 graphql_query_service: Arc<dyn GraphQLQueryService + Send + Sync>,
17 graphql_schema_manager: Arc<dyn GraphQLSchemaManager + Send + Sync>,
18}
19
20#[async_trait]
21#[component_alias]
22impl GraphQLSystem for GraphQLSystemImpl {
23 fn get_graphql_query_service(&self) -> Arc<dyn GraphQLQueryService + Send + Sync> {
24 self.graphql_query_service.clone()
25 }
26
27 fn get_graphql_schema_manager(&self) -> Arc<dyn GraphQLSchemaManager + Send + Sync> {
28 self.graphql_schema_manager.clone()
29 }
30}
31
32#[async_trait]
33impl Lifecycle for GraphQLSystemImpl {
34 async fn init(&self) {
35 self.graphql_schema_manager.init().await;
36 self.graphql_query_service.init().await;
37 }
38
39 async fn post_init(&self) {
40 self.graphql_schema_manager.post_init().await;
41 self.graphql_query_service.post_init().await;
42 }
43
44 async fn pre_shutdown(&self) {
45 self.graphql_query_service.pre_shutdown().await;
46 self.graphql_schema_manager.pre_shutdown().await;
47 }
48
49 async fn shutdown(&self) {
50 self.graphql_query_service.shutdown().await;
51 self.graphql_schema_manager.shutdown().await;
52 }
53}
54
55pub fn get_graphql_system() -> Arc<dyn GraphQLSystem + Send + Sync> {
56 let mut component_factory = get_shared_component_factory();
57 match TypedComponentInstanceProvider::primary_instance_typed::<dyn GraphQLSystem + Send + Sync>(&mut component_factory) {
58 Ok(runtime) => runtime,
59 Err(e) => {
60 panic!("{}", e);
61 }
62 }
63 }