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

Create a new instance of ObjectDef with a name.

Set the ObjectDef’s description field.

Add a directive on ObjectDef.

Set the object type as an extension

Push a Field to ObjectDef’s fields vector.

Add an interface ObjectDef implements.

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.