reactive_graph_server/server/
mod.rs1pub mod args;
2pub mod commands;
3#[cfg(target_os = "linux")]
4pub mod daemon;
5
6pub mod graphql_schema;
7pub mod json_schema;
8
9use std::time::Duration;
10
11use reactive_graph_runtime_impl::RuntimeBuilder;
12
13use crate::server::args::logging::init_logging;
14use crate::server::graphql_schema::print_graphql_schema_and_exit;
15use crate::server::json_schema::print_json_schema_and_exit;
16use args::ServerArguments;
17
18#[tokio::main]
19pub async fn server(args: ServerArguments) {
20 if let Some(commands) = &args.commands {
21 #[allow(unreachable_patterns, clippy::collapsible_match)]
22 match commands {
23 #[cfg(target_os = "linux")]
24 commands::ServerCommands::Daemon(_) => {
25 }
27 commands::ServerCommands::GraphqlSchema(args) => {
28 print_graphql_schema_and_exit(&args.commands).await;
29 }
30 commands::ServerCommands::JsonSchema(args) => {
31 print_json_schema_and_exit(&args.commands).await;
32 }
33 _ => {}
34 }
35 }
36 init_logging(&args);
37 run(args).await
38}
39
40pub async fn run(args: ServerArguments) {
41 RuntimeBuilder::new()
42 .instance_config(args.runtime.config_locations.instance_config)
44 .graphql_server_config(args.runtime.config_locations.graphql_config)
45 .plugins_config(args.runtime.config_locations.plugins_config)
46 .load_config_files()
47 .await
48 .instance_name(args.runtime.instance.name)
50 .instance_description(args.runtime.instance.description)
51 .hostname(args.runtime.graphql_server.hostname)
52 .port(args.runtime.graphql_server.port)
53 .secure(args.runtime.graphql_server.secure)
54 .ssl_certificate_path(args.runtime.graphql_server.ssl_certificate_path)
55 .ssl_private_key_path(args.runtime.graphql_server.ssl_private_key_path)
56 .shutdown_timeout(args.runtime.graphql_server.shutdown_timeout)
57 .workers(args.runtime.graphql_server.workers)
58 .default_context_path(args.runtime.graphql_server.default_context_path)
59 .disable_all_plugins(args.runtime.plugins.disable_all_plugins)
60 .disabled_plugins(args.runtime.plugins.disabled_plugins)
61 .enabled_plugins(args.runtime.plugins.enabled_plugins)
62 .disable_hot_deploy(args.runtime.plugins.disable_hot_deploy)
63 .hot_deploy_location(args.runtime.plugins.hot_deploy_location)
64 .install_location(args.runtime.plugins.install_location)
65 .init()
66 .await
67 .post_init()
68 .await
69 .spawn()
70 .await
71 .wait_for_stopped()
72 .await
73 .pre_shutdown()
74 .await
75 .shutdown()
76 .await
77 .wait_for(if args.runtime.stop_immediately.unwrap_or(false) {
79 Duration::from_millis(10)
80 } else {
81 Duration::from_secs(2)
82 })
83 .await;
84}