Skip to main content

FieldDefinition

Struct FieldDefinition 

Source
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: String

Field name - the key in the JSONB data column (e.g., “email”).

§field_type: FieldType

Field type.

§nullable: bool

Is 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

Source

pub fn new(name: impl Into<String>, field_type: FieldType) -> Self

Create a new required field.

Source

pub fn nullable(name: impl Into<String>, field_type: FieldType) -> Self

Create a new nullable field.

Source

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());
Source

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");
Source

pub fn with_description(self, desc: impl Into<String>) -> Self

Add description to field.

Source

pub fn with_default(self, value: Value) -> Self

Add default value to field.

Source

pub fn with_vector_config(self, config: VectorConfig) -> Self

Add vector configuration to field.

Source

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 unchanged
Source

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.

Source

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
Source

pub fn has_alias(&self) -> bool

Check if this field has an alias.

Source

pub fn is_vector(&self) -> bool

Check if this is a vector field.

Source

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());
Source

pub fn is_deprecated(&self) -> bool

Check if this field is deprecated.

Source

pub fn deprecation_reason(&self) -> Option<&str>

Get the deprecation reason if deprecated.

Trait Implementations§

Source§

impl Clone for FieldDefinition

Source§

fn clone(&self) -> FieldDefinition

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FieldDefinition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for FieldDefinition

Source§

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 FieldDefinition

Source§

fn eq(&self, other: &FieldDefinition) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for FieldDefinition

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for FieldDefinition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,