pub struct FieldDefinition {
pub name: String,
pub field_type: FieldType,
pub nullable: bool,
pub description: Option<String>,
pub default_value: Option<Value>,
pub vector_config: Option<VectorConfig>,
pub alias: Option<String>,
pub deprecation: Option<DeprecationInfo>,
pub requires_scope: Option<String>,
}Expand description
A field within a GraphQL type.
This represents a single field definition after compilation from Python/TypeScript 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, FieldType};
let field = FieldDefinition {
name: "email".to_string(),
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,
};Fields§
§name: StringField 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<Value>Default value (JSON representation).
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, FieldType};
let field = FieldDefinition {
name: "salary".to_string(),
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()),
};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 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: Value) -> Self
pub fn with_default(self, value: Value) -> Self
Add default value to field.
Sourcepub fn with_vector_config(self, config: VectorConfig) -> Self
pub 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 fn is_deprecated(&self) -> bool
pub 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.
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 more