pub struct DirectiveDefinition {
pub name: String,
pub description: Option<String>,
pub locations: Vec<DirectiveLocationKind>,
pub arguments: Vec<ArgumentDefinition>,
pub is_repeatable: bool,
}Expand description
A custom directive definition for schema extension.
Allows defining custom directives beyond the built-in @skip, @include,
and @deprecated directives. Custom directives are exposed via introspection
and can be evaluated at runtime via registered handlers.
§Example
use fraiseql_core::schema::{DirectiveDefinition, DirectiveLocationKind, ArgumentDefinition, FieldType};
let rate_limit = DirectiveDefinition {
name: "rateLimit".to_string(),
description: Some("Apply rate limiting to this field".to_string()),
locations: vec![DirectiveLocationKind::FieldDefinition],
arguments: vec![
ArgumentDefinition::new("limit", FieldType::Int),
ArgumentDefinition::optional("window", FieldType::String),
],
is_repeatable: false,
};Fields§
§name: StringDirective name (e.g., “rateLimit”, “auth”).
description: Option<String>Description of what this directive does.
locations: Vec<DirectiveLocationKind>Valid locations where this directive can be applied.
arguments: Vec<ArgumentDefinition>Arguments this directive accepts.
is_repeatable: boolWhether this directive can be applied multiple times to the same location.
Implementations§
Source§impl DirectiveDefinition
impl DirectiveDefinition
Sourcepub fn new(
name: impl Into<String>,
locations: Vec<DirectiveLocationKind>,
) -> Self
pub fn new( name: impl Into<String>, locations: Vec<DirectiveLocationKind>, ) -> Self
Create a new directive definition.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Set the description.
Sourcepub fn with_argument(self, arg: ArgumentDefinition) -> Self
pub fn with_argument(self, arg: ArgumentDefinition) -> Self
Add an argument to this directive.
Sourcepub fn with_arguments(self, args: Vec<ArgumentDefinition>) -> Self
pub fn with_arguments(self, args: Vec<ArgumentDefinition>) -> Self
Add multiple arguments to this directive.
Sourcepub fn repeatable(self) -> Self
pub fn repeatable(self) -> Self
Mark this directive as repeatable.
Sourcepub fn valid_at(&self, location: DirectiveLocationKind) -> bool
pub fn valid_at(&self, location: DirectiveLocationKind) -> bool
Check if this directive can be applied at the given location.
Sourcepub fn find_argument(&self, name: &str) -> Option<&ArgumentDefinition>
pub fn find_argument(&self, name: &str) -> Option<&ArgumentDefinition>
Find an argument by name.
Trait Implementations§
Source§impl Clone for DirectiveDefinition
impl Clone for DirectiveDefinition
Source§fn clone(&self) -> DirectiveDefinition
fn clone(&self) -> DirectiveDefinition
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DirectiveDefinition
impl Debug for DirectiveDefinition
Source§impl<'de> Deserialize<'de> for DirectiveDefinition
impl<'de> Deserialize<'de> for DirectiveDefinition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for DirectiveDefinition
impl PartialEq for DirectiveDefinition
Source§impl Serialize for DirectiveDefinition
impl Serialize for DirectiveDefinition
impl StructuralPartialEq for DirectiveDefinition
Auto Trait Implementations§
impl Freeze for DirectiveDefinition
impl RefUnwindSafe for DirectiveDefinition
impl Send for DirectiveDefinition
impl Sync for DirectiveDefinition
impl Unpin for DirectiveDefinition
impl UnsafeUnpin for DirectiveDefinition
impl UnwindSafe for DirectiveDefinition
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
Mutably borrows from an owned value. Read more