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 fn new() -> RequestValidator
pub fn new() -> RequestValidator
Create a new validator with default settings.
Sourcepub const fn from_config(config: &ComplexityConfig) -> RequestValidator
pub const fn from_config(config: &ComplexityConfig) -> RequestValidator
Create from a ComplexityConfig.
Sourcepub const fn with_max_depth(self, max_depth: usize) -> RequestValidator
pub const fn with_max_depth(self, max_depth: usize) -> RequestValidator
Set maximum query depth.
Sourcepub const fn with_max_complexity(
self,
max_complexity: usize,
) -> RequestValidator
pub const fn with_max_complexity( self, max_complexity: usize, ) -> RequestValidator
Set maximum query complexity.
Sourcepub const fn with_depth_validation(self, enabled: bool) -> RequestValidator
pub const fn with_depth_validation(self, enabled: bool) -> RequestValidator
Enable/disable depth validation.
Sourcepub const fn with_complexity_validation(self, enabled: bool) -> RequestValidator
pub const fn with_complexity_validation(self, enabled: bool) -> RequestValidator
Enable/disable complexity validation.
Sourcepub const fn with_max_aliases(self, max_aliases: usize) -> RequestValidator
pub const fn with_max_aliases(self, max_aliases: usize) -> RequestValidator
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 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_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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RequestValidator
impl Debug for RequestValidator
Source§impl Default for RequestValidator
impl Default for RequestValidator
Source§fn default() -> RequestValidator
fn default() -> RequestValidator
Auto Trait Implementations§
impl Freeze for RequestValidator
impl RefUnwindSafe for RequestValidator
impl Send for RequestValidator
impl Sync for RequestValidator
impl Unpin for RequestValidator
impl UnsafeUnpin for RequestValidator
impl UnwindSafe for RequestValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more