pub struct FragmentResolver { /* private fields */ }Expand description
Resolves GraphQL fragment spreads in query selection sets.
Handles fragment spreads (...FragmentName) by expanding them to their actual field selections.
Also merges multiple fragment definitions and handles field deduplication.
§Example
use fraiseql_core::graphql::{FragmentResolver, FragmentDefinition, FieldSelection};
let fragment = FragmentDefinition {
name: "UserFields".to_string(),
type_condition: "User".to_string(),
selections: vec![
FieldSelection {
name: "id".to_string(),
alias: None,
arguments: vec![],
nested_fields: vec![],
directives: vec![],
},
],
fragment_spreads: vec![],
};
let resolver = FragmentResolver::new(&[fragment]);Implementations§
Source§impl FragmentResolver
impl FragmentResolver
Sourcepub fn new(fragments: &[FragmentDefinition]) -> Self
pub fn new(fragments: &[FragmentDefinition]) -> Self
Create a new fragment resolver from a list of fragment definitions.
Sourcepub fn with_max_depth(self, max_depth: u32) -> Self
pub fn with_max_depth(self, max_depth: u32) -> Self
Create a resolver with a custom max depth.
Sourcepub fn resolve_spreads(
&self,
selections: &[FieldSelection],
) -> Result<Vec<FieldSelection>, FragmentError>
pub fn resolve_spreads( &self, selections: &[FieldSelection], ) -> Result<Vec<FieldSelection>, FragmentError>
Resolve all fragment spreads in selections.
§Errors
Returns error if:
- Fragment is not found
- Fragment depth exceeds maximum
- Circular references are detected
Sourcepub fn evaluate_inline_fragment(
selections: &[FieldSelection],
type_condition: Option<&str>,
actual_type: &str,
) -> Vec<FieldSelection>
pub fn evaluate_inline_fragment( selections: &[FieldSelection], type_condition: Option<&str>, actual_type: &str, ) -> Vec<FieldSelection>
Handle inline fragments with type conditions.
Evaluates whether an inline fragment applies based on type conditions. Returns the selections if the type condition matches, or an empty vector if it doesn’t.
Sourcepub fn merge_selections(
base: &[FieldSelection],
additional: Vec<FieldSelection>,
) -> Vec<FieldSelection>
pub fn merge_selections( base: &[FieldSelection], additional: Vec<FieldSelection>, ) -> Vec<FieldSelection>
Merge field selections from multiple sources (e.g., fragment spreads).
Handles:
- Combining fields from multiple fragments
- Deduplicating fields by name/alias
- Merging nested selections
Auto Trait Implementations§
impl Freeze for FragmentResolver
impl RefUnwindSafe for FragmentResolver
impl Send for FragmentResolver
impl Sync for FragmentResolver
impl Unpin for FragmentResolver
impl UnsafeUnpin for FragmentResolver
impl UnwindSafe for FragmentResolver
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
Mutably borrows from an owned value. Read more