pub struct QueryValidator { /* private fields */ }Expand description
Query Validator
Validates incoming GraphQL queries against security policies. Acts as the third layer in the security middleware pipeline.
Delegates AST-based analysis to RequestValidator from
graphql::complexity — the single source of truth for depth,
complexity, and alias-amplification logic.
Implementations§
Source§impl QueryValidator
impl QueryValidator
Sourcepub const fn from_config(config: QueryValidatorConfig) -> Self
pub const fn from_config(config: QueryValidatorConfig) -> Self
Create a new query validator from configuration
Sourcepub const fn permissive() -> Self
pub const fn permissive() -> Self
Create validator with permissive settings
Sourcepub fn validate(&self, query: &str) -> Result<QueryMetrics, SecurityError>
pub fn validate(&self, query: &str) -> Result<QueryMetrics, SecurityError>
Validate a GraphQL query, enforcing all configured limits.
Performs checks in order:
- Query size (O(1) — no parsing)
- AST parse (rejects malformed GraphQL)
- Query depth
- Query complexity
- Alias count (alias amplification protection)
Returns QueryMetrics if all checks pass, or the first
SecurityError encountered.
§Errors
Returns SecurityError::QueryTooLarge if the query exceeds max_size_bytes.
Returns SecurityError::MalformedQuery if GraphQL syntax is invalid.
Returns SecurityError::QueryTooDeep if nesting depth exceeds max_depth.
Returns SecurityError::QueryTooComplex if complexity exceeds max_complexity.
Returns SecurityError::TooManyAliases if alias count exceeds max_aliases.
Sourcepub const fn config(&self) -> &QueryValidatorConfig
pub const fn config(&self) -> &QueryValidatorConfig
Get the underlying configuration
Trait Implementations§
Source§impl Clone for QueryValidator
impl Clone for QueryValidator
Source§fn clone(&self) -> QueryValidator
fn clone(&self) -> QueryValidator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for QueryValidator
impl RefUnwindSafe for QueryValidator
impl Send for QueryValidator
impl Sync for QueryValidator
impl Unpin for QueryValidator
impl UnsafeUnpin for QueryValidator
impl UnwindSafe for QueryValidator
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