pub struct InputFieldDefinition {
pub name: String,
pub field_type: String,
pub nullable: bool,
pub description: Option<String>,
pub default_value: Option<String>,
pub deprecation: Option<DeprecationInfo>,
pub validation_rules: Vec<ValidationRule>,
}Expand description
A field within a GraphQL input object type.
§Example
use fraiseql_core::schema::InputFieldDefinition;
let field = InputFieldDefinition::new("email", "String")
.with_description("User's email address")
.with_nullable(false); // requiredFields§
§name: StringField name.
field_type: StringField type (e.g., "String!", "[Int]", "UserFilter").
nullable: boolWhether this input field is nullable (optional).
Drives required-field enforcement: a non-nullable field with no default
must be supplied (and non-null) by the client or the request is rejected
before the database call. Unlike the output FieldDefinition::nullable
(which defaults to false), this defaults to true — GraphQL input
fields are nullable unless explicitly marked non-null, and a missing key
degrades safely to “optional” (no enforcement) rather than over-rejecting.
description: Option<String>Description.
default_value: Option<String>Default value (as JSON string).
deprecation: Option<DeprecationInfo>Deprecation information (if this field is deprecated).
validation_rules: Vec<ValidationRule>Validation rules applied to this field (from @validate directives).
Implementations§
Source§impl InputFieldDefinition
impl InputFieldDefinition
Sourcepub fn new(name: impl Into<String>, field_type: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, field_type: impl Into<String>) -> Self
Create a new input field.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Set description.
Sourcepub const fn with_nullable(self, nullable: bool) -> Self
pub const fn with_nullable(self, nullable: bool) -> Self
Set whether this field is nullable (optional). Defaults to true.
Sourcepub fn with_default_value(self, value: impl Into<String>) -> Self
pub fn with_default_value(self, value: impl Into<String>) -> Self
Set default value.
Sourcepub fn deprecated(self, reason: Option<String>) -> Self
pub fn deprecated(self, reason: Option<String>) -> Self
Mark this field as deprecated.
Sourcepub const fn is_deprecated(&self) -> bool
pub const fn is_deprecated(&self) -> bool
Check if this field is deprecated.
Sourcepub const fn is_required(&self) -> bool
pub const fn is_required(&self) -> bool
Check if this field is required (non-nullable without default).
Driven by nullable, not the ! suffix of
field_type: a filter operator field can have a
non-null type (e.g. "[String!]!") yet be optional, so requiredness is
tracked separately from the type string.
Sourcepub fn with_validation_rule(self, rule: ValidationRule) -> Self
pub fn with_validation_rule(self, rule: ValidationRule) -> Self
Add a validation rule to this field.
Sourcepub fn with_validation_rules(self, rules: Vec<ValidationRule>) -> Self
pub fn with_validation_rules(self, rules: Vec<ValidationRule>) -> Self
Add multiple validation rules to this field.
Sourcepub const fn has_validation_rules(&self) -> bool
pub const fn has_validation_rules(&self) -> bool
Check if this field has validation rules.
Trait Implementations§
Source§impl Clone for InputFieldDefinition
impl Clone for InputFieldDefinition
Source§fn clone(&self) -> InputFieldDefinition
fn clone(&self) -> InputFieldDefinition
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more