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>
impl<'schema> FragmentRegistryBuilder<'schema>
Sourcepub fn add_fragment(
&mut self,
fragment: Fragment<'schema>,
) -> Result<(), FragmentRegistryBuildError>
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.
Sourcepub fn add_from_document_ast(
&mut self,
schema: &'schema Schema,
ast: &Document,
file_path: Option<&Path>,
) -> Result<(), Vec<FragmentBuildError>>
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.
Sourcepub fn add_from_document_file(
&mut self,
schema: &'schema Schema,
file_path: impl AsRef<Path>,
) -> Result<(), Vec<FragmentBuildError>>
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.
Sourcepub fn add_from_document_str(
&mut self,
schema: &'schema Schema,
content: impl AsRef<str>,
file_path: Option<&Path>,
) -> Result<(), Vec<FragmentBuildError>>
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.
Sourcepub fn build(
self,
) -> Result<FragmentRegistry<'schema>, Vec<FragmentRegistryBuildError>>
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.