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§
source§impl 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§
source§impl Clone for FragmentDefinition
impl Clone for FragmentDefinition
source§fn clone(&self) -> FragmentDefinition
fn clone(&self) -> FragmentDefinition
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for FragmentDefinition
impl Debug for FragmentDefinition
source§impl Display for FragmentDefinition
impl Display for FragmentDefinition
source§impl TryFrom<FragmentDefinition> for FragmentDefinition
impl TryFrom<FragmentDefinition> for FragmentDefinition
source§fn 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.