use std::sync::Arc;
#[cfg(feature = "arrow")]
use fraiseql_arrow::FraiseQLFlightService;
use fraiseql_core::{
runtime::{Executor, SubscriptionManager},
security::{AuthMiddleware, OidcValidator},
};
#[cfg(feature = "observers")]
use {
crate::observers::{ObserverRuntime, ObserverRuntimeConfig},
tokio::sync::RwLock,
};
#[cfg(feature = "auth")]
use crate::routes::{AuthMeState, AuthPkceState, auth_callback, auth_me, auth_start};
use crate::{
Result, ServerError,
middleware::{
BearerAuthState, OidcAuthState, RateLimiter, admin_auth_middleware, bearer_auth_middleware,
metrics_middleware, oidc_auth_middleware, require_json_content_type,
required_auth_middleware, trace_layer,
},
routes::{
PlaygroundState, SubscriptionState, api, graphql_get_handler, graphql_handler,
health_handler, introspection_handler, liveness_handler, metrics_handler,
metrics_json_handler, playground_handler, readiness_handler, subscription_handler,
},
server_config::ServerConfig,
tls::TlsSetup,
};
mod builder;
mod extensions;
#[cfg(feature = "functions-runtime")]
mod functions_setup;
pub(crate) mod initialization;
mod lifecycle;
mod routing;
#[cfg(test)]
mod parity_tests;
#[cfg(test)]
mod routing_tests;
#[cfg(test)]
mod tests;
#[cfg(feature = "rest")]
pub(super) type RestRouterBuilder = Arc<
dyn Fn(
&crate::routes::graphql::AppState,
&crate::routes::rest::RestMountConfig,
) -> Option<axum::Router>
+ Send
+ Sync,
>;
pub struct Server {
pub(super) config: ServerConfig,
pub(super) executor: Arc<Executor>,
pub(super) subscription_manager: Arc<SubscriptionManager>,
pub(super) subscription_lifecycle: Arc<dyn crate::subscriptions::SubscriptionLifecycle>,
pub(super) subscription_drain: Arc<tokio::sync::watch::Sender<bool>>,
pub(super) max_subscriptions_per_connection: Option<u32>,
pub(super) oidc_validator: Option<Arc<OidcValidator>>,
pub(super) hs256_auth: Option<Arc<AuthMiddleware>>,
pub(super) rate_limiter: Option<Arc<RateLimiter>>,
#[cfg(feature = "secrets")]
pub(super) secrets_manager: Option<Arc<crate::secrets_manager::SecretsManager>>,
#[cfg(feature = "federation")]
pub(super) circuit_breaker:
Option<Arc<crate::federation::circuit_breaker::FederationCircuitBreakerManager>>,
pub(super) error_sanitizer: Arc<crate::config::error_sanitization::ErrorSanitizer>,
#[cfg(feature = "auth")]
pub(super) state_encryption: Option<Arc<crate::auth::state_encryption::StateEncryptionService>>,
#[cfg(feature = "auth")]
pub(super) pkce_store: Option<Arc<crate::auth::PkceStateStore>>,
#[cfg(feature = "auth")]
pub(super) oidc_server_client: Option<Arc<crate::auth::OidcServerClient>>,
#[cfg(feature = "auth")]
pub(super) social_login: Option<Arc<crate::auth::MultiProviderAuthState>>,
#[cfg(feature = "auth")]
pub(super) anon_signup_state: Option<Arc<crate::auth::AnonSignupState>>,
#[cfg(feature = "auth")]
pub(super) mfa_state: Option<Arc<crate::auth::MfaRouteState>>,
#[cfg(feature = "auth")]
pub(super) otp_state: Option<Arc<crate::auth::OtpRouteState>>,
#[cfg(feature = "auth")]
pub(super) local_password_state: Option<Arc<crate::auth::LocalPasswordRouteState>>,
#[cfg(feature = "auth")]
pub(super) email_verification_state: Option<Arc<crate::auth::EmailVerificationRouteState>>,
#[cfg(feature = "auth")]
pub(super) session_state: Option<Arc<fraiseql_auth::session_state::SessionState>>,
pub(super) async_operations: Option<crate::async_operations::AsyncOperationsRuntime>,
pub(super) api_key_authenticator: Option<Arc<crate::api_key::ApiKeyAuthenticator>>,
#[cfg(feature = "auth-saml")]
pub(super) saml_state: Option<fraiseql_auth::saml::SamlAuthState>,
pub(super) service_account_authenticator:
Option<Arc<crate::service_account::ServiceAccountAuthenticator>>,
#[allow(dead_code)] pub(super) revocation_manager: Option<Arc<crate::token_revocation::TokenRevocationManager>>,
pub(super) apq_store: Option<fraiseql_core::apq::ArcApqStorage>,
pub(super) trusted_docs: Option<Arc<crate::trusted_documents::TrustedDocumentStore>>,
#[cfg(feature = "observers")]
pub(super) observer_runtime: Option<Arc<RwLock<ObserverRuntime>>>,
#[cfg(feature = "observers")]
pub(super) entity_event_fanout: Option<crate::subscriptions::EntityEventFanout>,
#[cfg(feature = "observers")]
pub(super) stream_replay:
Option<std::sync::Arc<fraiseql_observers::listener::ChangeLogReplayReader>>,
#[cfg(feature = "observers")]
pub(super) db_pool: Option<sqlx::PgPool>,
#[cfg(feature = "cdc-outbound")]
pub(super) cdc_drains: Vec<crate::cdc_outbound::SinkDrain>,
#[cfg(feature = "inbound")]
pub(super) webhook_routes: crate::inbound::WebhookRoutes,
#[cfg(feature = "subscription-kafka")]
pub(super) subscription_kafka: Option<crate::subscription_kafka::SubscriptionKafkaMirror>,
#[cfg(feature = "auth")]
#[allow(dead_code)] pub(super) enrichment_pool: Option<sqlx::PgPool>,
#[cfg(feature = "arrow")]
pub(super) flight_service: Option<FraiseQLFlightService>,
#[cfg(feature = "mcp")]
pub(super) mcp_config: Option<fraiseql_core::schema::McpConfig>,
pub(super) storage_state: Option<fraiseql_storage::StorageState>,
#[cfg(feature = "functions-runtime")]
pub(super) functions_hooks: Option<Arc<crate::subsystems::BeforeMutationHooks>>,
#[cfg(feature = "functions-runtime")]
pub(super) functions_config: Option<crate::schema::loader::FunctionsConfig>,
pub(super) tenant_executor_factory: Option<crate::tenancy::TenantExecutorFactory>,
#[cfg(feature = "rest")]
pub(super) rest_router_builder: Option<RestRouterBuilder>,
pub(super) pool_tuning_config: Option<crate::config::pool_tuning::PoolPressureMonitorConfig>,
pub(super) adapter_cache_enabled: bool,
pub(super) storage_max_upload_bytes: usize,
pub(super) usage: Arc<crate::usage::aggregator::UsageAggregator>,
pub(super) tasks: tokio::task::JoinSet<()>,
}