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 Clone for ObjectDefinition
impl Clone for ObjectDefinition
Source§fn clone(&self) -> ObjectDefinition
fn clone(&self) -> ObjectDefinition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§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.