Struct apollo_encoder::FragmentDefinition
source · [−]pub struct FragmentDefinition { /* private fields */ }
Expand description
The FragmentDefinition type represents a fragment definition
FragmentDefinition: fragment FragmentName TypeCondition Directives? SelectionSet
Detailed documentation can be found in GraphQL spec.
Example
use apollo_encoder::{Field, FragmentDefinition, Selection, SelectionSet, TypeCondition};
use indoc::indoc;
let selections = vec![Selection::Field(Field::new(String::from("myField")))];
let mut selection_set = SelectionSet::new();
selections
.into_iter()
.for_each(|s| selection_set.selection(s));
let mut fragment_def = FragmentDefinition::new(
String::from("myFragment"),
TypeCondition::new(String::from("User")),
selection_set,
);
assert_eq!(
fragment_def.to_string(),
indoc! {r#"
fragment myFragment on User {
myField
}
"#}
);
Implementations
sourceimpl FragmentDefinition
impl FragmentDefinition
sourcepub fn new(
name: String,
type_condition: TypeCondition,
selection_set: SelectionSet
) -> Self
pub fn new(
name: String,
type_condition: TypeCondition,
selection_set: SelectionSet
) -> Self
Create an instance of FragmentDefinition.
Trait Implementations
sourceimpl Debug for FragmentDefinition
impl Debug for FragmentDefinition
sourceimpl Display for FragmentDefinition
impl Display for FragmentDefinition
sourceimpl TryFrom<FragmentDefinition> for FragmentDefinition
impl TryFrom<FragmentDefinition> for FragmentDefinition
sourcefn try_from(node: FragmentDefinition) -> Result<Self, Self::Error>
fn try_from(node: FragmentDefinition) -> Result<Self, Self::Error>
Create an apollo-encoder node from an apollo-parser one.
Errors
This returns an error if the apollo-parser tree is not valid. The error doesn’t have much context due to TryFrom API constraints: validate the parse tree before using TryFrom if granular errors are important to you.
type Error = FromError
type Error = FromError
The type returned in the event of a conversion error.
Auto Trait Implementations
impl RefUnwindSafe for FragmentDefinition
impl Send for FragmentDefinition
impl Sync for FragmentDefinition
impl Unpin for FragmentDefinition
impl UnwindSafe for FragmentDefinition
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more