pub struct FieldDefinition {
pub name: FieldName,
pub field_type: FieldType,
pub nullable: bool,
pub description: Option<String>,
pub default_value: Option<GraphQLValue>,
pub vector_config: Option<VectorConfig>,
pub alias: Option<String>,
pub deprecation: Option<DeprecationInfo>,
pub requires_scope: Option<String>,
pub on_deny: FieldDenyPolicy,
pub encryption: Option<FieldEncryptionConfig>,
}Expand description
A field within a GraphQL type.
This represents a single field definition after compilation from authoring-language decorators. All data is Rust-owned.
§JSONB Architecture Note
FraiseQL stores all field data in a JSONB column (typically data).
The name field corresponds to the key in the JSONB object.
SQL columns are only used for WHERE clause filtering, not data retrieval.
§Example
use fraiseql_core::schema::{FieldDefinition, FieldDenyPolicy, FieldType};
let field = FieldDefinition {
name: "email".into(),
field_type: FieldType::String,
nullable: true,
description: Some("User's email address".to_string()),
default_value: None,
vector_config: None,
alias: None,
deprecation: None,
requires_scope: None,
on_deny: FieldDenyPolicy::default(),
encryption: None,
};Fields§
§name: FieldNameField name - the key in the JSONB data column (e.g., “email”).
field_type: FieldTypeField type.
nullable: boolIs this field nullable?
description: Option<String>Optional description (from docstring).
default_value: Option<GraphQLValue>Default value.
vector_config: Option<VectorConfig>Vector configuration (for pgvector fields).
Only present when field_type is Vector.
alias: Option<String>GraphQL alias for this field (output key name in response).
When set, the field value from JSONB key name is output under this alias.
Example: { writer: author { name } } - reads JSONB key “author”, outputs as “writer”
deprecation: Option<DeprecationInfo>Deprecation information (from @deprecated directive). When set, the field is marked as deprecated in the schema.
requires_scope: Option<String>Scope required to access this field (field-level access control).
When set, users must have this scope in their JWT to query this field.
The runtime FieldFilter validates these requirements.
§Example
use fraiseql_core::schema::{FieldDefinition, FieldDenyPolicy, FieldType};
let field = FieldDefinition {
name: "salary".into(),
field_type: FieldType::Int,
nullable: false,
description: None,
default_value: None,
vector_config: None,
alias: None,
deprecation: None,
requires_scope: Some("read:Employee.salary".to_string()),
on_deny: FieldDenyPolicy::Reject,
encryption: None,
};on_deny: FieldDenyPolicyPolicy when a user lacks the required scope for this field.
Reject(default): the entire query fails with aFORBIDDENerror.Mask: the query succeeds but this field returnsnull.
encryption: Option<FieldEncryptionConfig>Encryption configuration for this field.
When set, the field’s value is transparently encrypted before being
stored in the database and decrypted when read back. Encryption
uses the key referenced by key_reference (fetched from the secrets
manager) with the specified algorithm.
Implementations§
Source§impl FieldDefinition
impl FieldDefinition
Sourcepub fn new(name: impl Into<String>, field_type: FieldType) -> Self
pub fn new(name: impl Into<String>, field_type: FieldType) -> Self
Create a new required field.
Sourcepub fn nullable(name: impl Into<String>, field_type: FieldType) -> Self
pub fn nullable(name: impl Into<String>, field_type: FieldType) -> Self
Create a new nullable field.
Sourcepub fn vector(name: impl Into<String>, config: VectorConfig) -> Self
pub fn vector(name: impl Into<String>, config: VectorConfig) -> Self
Create a new vector field.
§Example
use fraiseql_core::schema::{FieldDefinition, VectorConfig};
let embedding = FieldDefinition::vector("embedding", VectorConfig::openai());Sourcepub fn with_requires_scope(self, scope: impl Into<String>) -> Self
pub fn with_requires_scope(self, scope: impl Into<String>) -> Self
Add a scope requirement to the field (field-level access control).
§Example
use fraiseql_core::schema::{FieldDefinition, FieldType};
let salary = FieldDefinition::new("salary", FieldType::Int)
.with_requires_scope("read:Employee.salary");Sourcepub const fn with_on_deny(self, policy: FieldDenyPolicy) -> Self
pub const fn with_on_deny(self, policy: FieldDenyPolicy) -> Self
Set the deny policy for when a user lacks the required scope.
Sourcepub fn with_description(self, desc: impl Into<String>) -> Self
pub fn with_description(self, desc: impl Into<String>) -> Self
Add description to field.
Sourcepub fn with_default(self, value: GraphQLValue) -> Self
pub fn with_default(self, value: GraphQLValue) -> Self
Add default value to field.
Sourcepub const fn with_vector_config(self, config: VectorConfig) -> Self
pub const fn with_vector_config(self, config: VectorConfig) -> Self
Add vector configuration to field.
Sourcepub fn with_alias(self, alias: impl Into<String>) -> Self
pub fn with_alias(self, alias: impl Into<String>) -> Self
Set a GraphQL alias for this field (output key name in response).
The alias determines the key name in the JSON response, while name
remains the JSONB key where data is read from.
§Example
use fraiseql_core::schema::{FieldDefinition, FieldType};
// JSONB key "author" will be output as "writer" in the response
let field = FieldDefinition::new("author", FieldType::Object("User".to_string()))
.with_alias("writer");
assert_eq!(field.output_name(), "writer");
assert_eq!(field.name, "author"); // JSONB key unchangedSourcepub fn output_name(&self) -> &str
pub fn output_name(&self) -> &str
Get the output name for this field (alias if set, otherwise name).
This is the key name that appears in the GraphQL JSON response.
Sourcepub fn jsonb_key(&self) -> &str
pub fn jsonb_key(&self) -> &str
Get the JSONB key name for this field.
This is always name, regardless of alias. Used for:
- Reading data from JSONB column
- Building WHERE clause paths
Sourcepub fn deprecated(self, reason: Option<String>) -> Self
pub fn deprecated(self, reason: Option<String>) -> Self
Mark this field as deprecated.
§Example
use fraiseql_core::schema::{FieldDefinition, FieldType};
let field = FieldDefinition::new("oldId", FieldType::Int)
.deprecated(Some("Use 'id' instead".to_string()));
assert!(field.is_deprecated());Sourcepub const fn is_deprecated(&self) -> bool
pub const fn is_deprecated(&self) -> bool
Check if this field is deprecated.
Sourcepub fn deprecation_reason(&self) -> Option<&str>
pub fn deprecation_reason(&self) -> Option<&str>
Get the deprecation reason if deprecated.
Sourcepub fn with_encryption(self, config: FieldEncryptionConfig) -> Self
pub fn with_encryption(self, config: FieldEncryptionConfig) -> Self
Add encryption configuration to this field.
Sourcepub const fn is_encrypted(&self) -> bool
pub const fn is_encrypted(&self) -> bool
Check if this field is encrypted.
Sourcepub fn is_primary_key(&self) -> bool
pub fn is_primary_key(&self) -> bool
Whether this field is a primary key (name starts with “pk_” or equals “id”).
Trait Implementations§
Source§impl Clone for FieldDefinition
impl Clone for FieldDefinition
Source§fn clone(&self) -> FieldDefinition
fn clone(&self) -> FieldDefinition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FieldDefinition
impl Debug for FieldDefinition
Source§impl<'de> Deserialize<'de> for FieldDefinition
impl<'de> Deserialize<'de> for FieldDefinition
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>,
Source§impl PartialEq for FieldDefinition
impl PartialEq for FieldDefinition
Source§impl Serialize for FieldDefinition
impl Serialize for FieldDefinition
impl StructuralPartialEq for FieldDefinition
Auto Trait Implementations§
impl Freeze for FieldDefinition
impl RefUnwindSafe for FieldDefinition
impl Send for FieldDefinition
impl Sync for FieldDefinition
impl Unpin for FieldDefinition
impl UnsafeUnpin for FieldDefinition
impl UnwindSafe for FieldDefinition
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