FragmentRegistryBuilder

Struct FragmentRegistryBuilder 

Source
pub struct FragmentRegistryBuilder<'schema> { /* private fields */ }
Expand description

Builder for constructing a FragmentRegistry with validation.

The FragmentRegistryBuilder allows you to incrementally add fragments from multiple sources (files, strings, AST) and then build an immutable FragmentRegistry with comprehensive validation including cycle detection and reference checking.

§Example

use libgraphql_core::schema::SchemaBuilder;
use libgraphql_core::operation::FragmentRegistryBuilder;

let schema = SchemaBuilder::from_str(
    None,
    "type Query { hello: String }"
)?
.build()?;

let mut builder = FragmentRegistryBuilder::new();

builder.add_from_document_str(
    &schema,
    "fragment UserFields on User { id name }",
    None
).unwrap();

builder.add_from_document_str(
    &schema,
    "fragment PostFields on Post { title body }",
    None
).unwrap();

let registry = builder.build().unwrap();

Implementations§

Source§

impl<'schema> FragmentRegistryBuilder<'schema>

Source

pub fn new() -> Self

Create a new empty FragmentRegistryBuilder.

Source

pub fn add_fragment( &mut self, fragment: Fragment<'schema>, ) -> Result<(), FragmentRegistryBuildError>

Add a pre-built fragment to the registry.

Returns an error if a fragment with the same name already exists.

Source

pub fn add_from_document_ast( &mut self, schema: &'schema Schema, ast: &Document, file_path: Option<&Path>, ) -> Result<(), Vec<FragmentBuildError>>

Parse fragments from an AST document and add them to the builder.

This method follows the pattern of QueryBuilder::from_ast.

Only fragment definitions in the document are processed; operation definitions are ignored.

Source

pub fn add_from_document_file( &mut self, schema: &'schema Schema, file_path: impl AsRef<Path>, ) -> Result<(), Vec<FragmentBuildError>>

Parse fragments from a file and add them to the builder.

This method follows the pattern of QueryBuilder::from_file.

Source

pub fn add_from_document_str( &mut self, schema: &'schema Schema, content: impl AsRef<str>, file_path: Option<&Path>, ) -> Result<(), Vec<FragmentBuildError>>

Parse fragments from a string and add them to the builder.

This method follows the pattern of QueryBuilder::from_str.

Source

pub fn build( self, ) -> Result<FragmentRegistry<'schema>, Vec<FragmentRegistryBuildError>>

Build the immutable FragmentRegistry with comprehensive validation.

This method performs the following validations:

  • Detects cycles in fragment spreads
  • Deduplicates phase-shifted cycles (e.g., A→B→C→A is the same as B→C→A→B)
  • Validates that all fragment references exist

If any validation errors are found, returns all errors at once rather than failing on the first error.

Trait Implementations§

Source§

impl<'schema> Debug for FragmentRegistryBuilder<'schema>

Source§

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

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

impl<'schema> Default for FragmentRegistryBuilder<'schema>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'schema> Freeze for FragmentRegistryBuilder<'schema>

§

impl<'schema> RefUnwindSafe for FragmentRegistryBuilder<'schema>

§

impl<'schema> Send for FragmentRegistryBuilder<'schema>

§

impl<'schema> Sync for FragmentRegistryBuilder<'schema>

§

impl<'schema> Unpin for FragmentRegistryBuilder<'schema>

§

impl<'schema> UnwindSafe for FragmentRegistryBuilder<'schema>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.