fraiseql_server/lib.rs
1//! FraiseQL HTTP Server
2//!
3//! HTTP server for FraiseQL v2 compiled GraphQL execution engine.
4//!
5//! # Architecture
6//!
7//! The server exposes a GraphQL HTTP endpoint that:
8//! 1. Receives GraphQL queries via POST
9//! 2. Executes queries using the runtime Executor
10//! 3. Returns GraphQL-compliant JSON responses
11//!
12//! # Features
13//!
14//! - GraphQL endpoint (`/graphql`)
15//! - Health check endpoint (`/health`)
16//! - Schema introspection endpoint (`/introspection`)
17//! - CORS support
18//! - Compression (gzip, br, zstd)
19//! - Request tracing
20//! - APQ (Automatic Persisted Queries)
21//! - Query caching
22//! - Authentication middleware (optional)
23
24#![forbid(unsafe_code)]
25
26// API key authentication
27pub mod api_key;
28// Token revocation
29pub mod token_revocation;
30
31// Original fraiseql-server modules
32pub mod api;
33pub mod error;
34pub mod extractors;
35#[cfg(feature = "federation")]
36pub mod federation;
37pub mod logging;
38pub mod middleware;
39pub mod routes;
40pub mod schema;
41pub mod server;
42pub mod server_config;
43pub mod subscriptions;
44pub mod validation;
45
46// Renamed to avoid conflicts with runtime modules
47pub mod metrics_server;
48
49// fraiseql-runtime modules (merged)
50
51/// Runtime configuration types loaded from `fraiseql.toml` or environment variables.
52pub mod config;
53/// Resilience primitives: backpressure and retry policies.
54pub mod resilience;
55/// Utilities for distributed tracing, span propagation, and trace context formatting.
56#[cfg(feature = "federation")]
57pub mod tracing_utils;
58#[cfg(not(feature = "federation"))]
59pub mod tracing_utils {
60 //! Stub tracing utilities when federation is disabled.
61 use axum::http::HeaderMap;
62
63 /// Stub trace context extraction when federation is disabled.
64 #[allow(clippy::missing_const_for_fn)] // Reason: signature must match federation-enabled version which is not const
65 pub fn extract_trace_context(_headers: &HeaderMap) -> Option<()> {
66 None
67 }
68}
69
70// Webhooks (extracted to fraiseql-webhooks crate) — optional, enable with `features = ["webhooks"]`
71// Authentication (extracted to fraiseql-auth crate) — optional, enable with `features =
72// ["auth"]`
73#[cfg(feature = "auth")]
74pub use fraiseql_auth as auth;
75#[cfg(feature = "webhooks")]
76pub use fraiseql_webhooks as webhooks;
77
78/// Stub auth types compiled when the `auth` feature is disabled.
79///
80/// These zero-sized types allow internal code that references `crate::auth::*` to compile
81/// in no-auth builds without requiring every call-site to be cfg-gated. All stub methods
82/// are pure stubs that the compiler will dead-code-eliminate.
83#[cfg(not(feature = "auth"))]
84pub mod auth {
85 use std::sync::Arc;
86
87 /// Stub for `fraiseql_auth::state_encryption::StateEncryptionService`.
88 pub mod state_encryption {
89 /// Zero-sized stub; never instantiated when `auth` feature is off.
90 pub struct StateEncryptionService;
91 impl StateEncryptionService {
92 /// Stub: returns `None`.
93 ///
94 /// # Errors
95 ///
96 /// Currently infallible — always returns `Ok(None)`.
97 /// Errors may be returned when the `auth` feature is enabled.
98 pub fn from_compiled_schema(
99 _s: &serde_json::Value,
100 ) -> crate::Result<Option<std::sync::Arc<Self>>> {
101 Ok(None)
102 }
103 }
104 }
105
106 /// Stub for `fraiseql_auth::PkceStateStore`.
107 pub struct PkceStateStore;
108 impl PkceStateStore {
109 /// Stub: always returns `true` (in-memory).
110 pub fn is_in_memory(&self) -> bool {
111 true
112 }
113
114 /// Stub: no-op.
115 pub async fn cleanup_expired(&self) {}
116 }
117
118 /// Stub for `fraiseql_auth::OidcServerClient`.
119 pub struct OidcServerClient;
120 impl OidcServerClient {
121 /// Stub: always returns `None`.
122 pub fn from_compiled_schema(_schema_json: &serde_json::Value) -> Option<Arc<Self>> {
123 None
124 }
125 }
126}
127
128// Secrets management and encryption (extracted to fraiseql-secrets crate) — optional, enable with
129// `features = ["secrets"]`
130#[cfg(feature = "secrets")]
131pub use fraiseql_secrets::{encryption, secrets_manager};
132
133// TLS/SSL and encryption
134pub mod tls;
135
136// Observer management - optional
137#[cfg(feature = "observers")]
138pub mod observers;
139
140// Arrow Flight integration - optional
141#[cfg(feature = "arrow")]
142pub mod arrow;
143
144// MCP (Model Context Protocol) server - optional
145#[cfg(feature = "mcp")]
146pub mod mcp;
147
148// Connection pool management and auto-tuning
149pub mod pool;
150
151// Object storage backends (local, S3, GCS, Azure Blob)
152pub mod storage;
153
154// Trusted documents (query allowlist)
155pub mod trusted_documents;
156
157// Testing utilities
158#[cfg(any(test, feature = "testing"))]
159pub mod testing;
160
161pub use logging::{
162 ErrorDetails, LogLevel, LogMetrics, RequestContext, RequestId, RequestLogger, SourceLocation,
163 StructuredLogEntry,
164};
165pub use metrics_server::{MetricsCollector, PrometheusMetrics};
166pub use schema::CompiledSchemaLoader;
167pub use server::Server;
168pub use server_config::ServerConfig;
169pub use tls::TlsSetup;
170pub use validation::{ComplexityValidationError, RequestValidator};
171
172/// Convenience re-exports for common server types.
173///
174/// ```rust
175/// use fraiseql_server::prelude::*;
176/// ```
177pub mod prelude {
178 pub use fraiseql_core::schema::CompiledSchema;
179
180 pub use crate::{
181 ComplexityValidationError, RequestValidator, Server, ServerConfig, ServerError, TlsSetup,
182 };
183}
184
185/// Server error type.
186#[derive(Debug, thiserror::Error)]
187#[non_exhaustive]
188pub enum ServerError {
189 /// Server binding error.
190 #[error("Failed to bind server: {0}")]
191 BindError(String),
192
193 /// Configuration error.
194 #[error("Configuration error: {0}")]
195 ConfigError(String),
196
197 /// Runtime error.
198 #[error("Runtime error: {0}")]
199 RuntimeError(#[from] fraiseql_core::error::FraiseQLError),
200
201 /// IO error.
202 #[error("IO error: {0}")]
203 IoError(#[from] std::io::Error),
204
205 /// Database error.
206 #[error("Database error: {0}")]
207 Database(String),
208
209 /// Validation error.
210 #[error("Validation error: {0}")]
211 Validation(String),
212
213 /// Resource conflict error.
214 #[error("Conflict: {0}")]
215 Conflict(String),
216
217 /// Resource not found error.
218 #[error("Not found: {0}")]
219 NotFound(String),
220}
221
222/// Server result type.
223pub type Result<T> = std::result::Result<T, ServerError>;