pub struct RequestValidator { /* private fields */ }Expand description
AST-based GraphQL request validator.
Uses graphql-parser to walk the full document tree. Correctly handles
operation names, arguments, fragment spreads, inline fragments, and aliases —
none of which a character-scan can distinguish from field names.
Implementations§
Source§impl RequestValidator
impl RequestValidator
Sourcepub const fn from_config(config: &ComplexityConfig) -> Self
pub const fn from_config(config: &ComplexityConfig) -> Self
Create from a ComplexityConfig.
Sourcepub const fn with_max_depth(self, max_depth: usize) -> Self
pub const fn with_max_depth(self, max_depth: usize) -> Self
Set maximum query depth.
Sourcepub const fn with_max_complexity(self, max_complexity: usize) -> Self
pub const fn with_max_complexity(self, max_complexity: usize) -> Self
Set maximum query complexity.
Sourcepub const fn with_depth_validation(self, enabled: bool) -> Self
pub const fn with_depth_validation(self, enabled: bool) -> Self
Enable/disable depth validation.
Sourcepub const fn with_complexity_validation(self, enabled: bool) -> Self
pub const fn with_complexity_validation(self, enabled: bool) -> Self
Enable/disable complexity validation.
Sourcepub const fn with_max_aliases(self, max_aliases: usize) -> Self
pub const fn with_max_aliases(self, max_aliases: usize) -> Self
Set maximum number of aliases per query.
Sourcepub fn analyze(
&self,
query: &str,
) -> Result<QueryMetrics, ComplexityValidationError>
pub fn analyze( &self, query: &str, ) -> Result<QueryMetrics, ComplexityValidationError>
Compute query metrics without enforcing any limits.
Returns QueryMetrics for the query.
Used by CLI tooling (explain, cost commands) where raw metrics
are needed without a hard rejection.
§Errors
Returns ComplexityValidationError::MalformedQuery if the query cannot be parsed.
Sourcepub const fn is_no_op(&self) -> bool
pub const fn is_no_op(&self) -> bool
Returns true when every configured validation knob is disabled and the expensive AST parse can be skipped entirely.
A validator is “fully disabled” only when depth, complexity, AND alias
checks are all off. The alias-amplification check is a distinct DoS
vector — max_aliases_per_query == 0 disables it, any other value
keeps it active even when depth/complexity validation are turned off.
Sourcepub fn validate_query(
&self,
query: &str,
) -> Result<(), ComplexityValidationError>
pub fn validate_query( &self, query: &str, ) -> Result<(), ComplexityValidationError>
Validate a GraphQL query string, enforcing configured limits.
§Errors
Returns ComplexityValidationError if the query violates any validation rules.
Sourcepub fn validate_query_doc<'a>(
&self,
document: &'a Document<'a, String>,
) -> Result<(), ComplexityValidationError>
pub fn validate_query_doc<'a>( &self, document: &'a Document<'a, String>, ) -> Result<(), ComplexityValidationError>
Validate an already-parsed GraphQL document, enforcing configured limits.
This is the AST-only entry point used by the server’s HTTP handler so the
document is parsed exactly once per request (rather than once by the
validator and once by the executor’s matcher). See F001 in
IMPROVEMENTS.md.
§Errors
Returns ComplexityValidationError if the document violates depth,
complexity, or alias-amplification limits.
Sourcepub fn validate_variables(
&self,
variables: Option<&Value>,
) -> Result<(), ComplexityValidationError>
pub fn validate_variables( &self, variables: Option<&Value>, ) -> Result<(), ComplexityValidationError>
Validate variables JSON.
§Errors
Returns ComplexityValidationError if variables are not a JSON object or exceed
MAX_VARIABLES_COUNT.
§Panics
Cannot panic in practice — the expect on as_object() is guarded
by a preceding is_object() check that returns Err first.
Trait Implementations§
Source§impl Clone for RequestValidator
impl Clone for RequestValidator
Source§fn clone(&self) -> RequestValidator
fn clone(&self) -> RequestValidator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more