Struct apollo_encoder::ObjectDef [−][src]
pub struct ObjectDef { /* fields omitted */ }Expand description
Object 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_, Field, ObjectDef};
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 = Field::new("toys".to_string(), ty_2);
field.deprecated(Some("Cats are too spoiled".to_string()));
let ty_3 = Type_::NamedType {
name: "FoodType".to_string(),
};
let mut field_2 = Field::new("food".to_string(), ty_3);
field_2.description(Some("Dry or wet food?".to_string()));
let ty_4 = Type_::NamedType {
name: "Boolean".to_string(),
};
let field_3 = Field::new("catGrass".to_string(), ty_4);
let mut object_def = ObjectDef::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] @deprecated(reason: "Cats are too spoiled")
"Dry or wet food?"
food: FoodType
catGrass: Boolean
}
"#}
);Implementations
Set the ObjectDef’s description field.