Struct apollo_encoder::ObjectDefinition
source · pub struct ObjectDefinition { /* private fields */ }
Expand description
ObjectDefinition types represent concrete instantiations of sets of fields.
The introspection types (e.g. __Type
, __Field
, etc) are examples of
objects.
ObjectTypeDefinition: Description? type Name ImplementsInterfaces? Directives? FieldsDefinition?
Detailed documentation can be found in GraphQL spec.
Example
use apollo_encoder::{Type_, FieldDefinition, ObjectDefinition};
use indoc::indoc;
let ty_1 = Type_::NamedType {
name: "DanglerPoleToys".to_string(),
};
let ty_2 = Type_::List { ty: Box::new(ty_1) };
let mut field = FieldDefinition::new("toys".to_string(), ty_2);
let ty_3 = Type_::NamedType {
name: "FoodType".to_string(),
};
let mut field_2 = FieldDefinition::new("food".to_string(), ty_3);
field_2.description("Dry or wet food?".to_string());
let ty_4 = Type_::NamedType {
name: "Boolean".to_string(),
};
let field_3 = FieldDefinition::new("catGrass".to_string(), ty_4);
let mut object_def = ObjectDefinition::new("PetStoreTrip".to_string());
object_def.field(field);
object_def.field(field_2);
object_def.field(field_3);
object_def.interface("ShoppingTrip".to_string());
assert_eq!(
object_def.to_string(),
indoc! { r#"
type PetStoreTrip implements ShoppingTrip {
toys: [DanglerPoleToys]
"Dry or wet food?"
food: FoodType
catGrass: Boolean
}
"#}
);
Implementations§
source§impl ObjectDefinition
impl ObjectDefinition
sourcepub fn description(&mut self, description: String)
pub fn description(&mut self, description: String)
Set the ObjectDef’s description field.
sourcepub fn field(&mut self, field: FieldDefinition)
pub fn field(&mut self, field: FieldDefinition)
Push a Field to ObjectDef’s fields vector.
Trait Implementations§
source§impl Debug for ObjectDefinition
impl Debug for ObjectDefinition
source§impl Display for ObjectDefinition
impl Display for ObjectDefinition
source§impl TryFrom<ObjectTypeDefinition> for ObjectDefinition
impl TryFrom<ObjectTypeDefinition> for ObjectDefinition
source§fn try_from(node: ObjectTypeDefinition) -> Result<Self, Self::Error>
fn try_from(node: ObjectTypeDefinition) -> 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.
source§impl TryFrom<ObjectTypeExtension> for ObjectDefinition
impl TryFrom<ObjectTypeExtension> for ObjectDefinition
source§fn try_from(node: ObjectTypeExtension) -> Result<Self, Self::Error>
fn try_from(node: ObjectTypeExtension) -> 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.