pub struct EnumDefinition { /* private fields */ }
Expand description
Enums are special scalars that can only have a defined set of values.
EnumTypeDefinition: Description? enum Name Directives? EnumValuesDefinition?
Detailed documentation can be found in GraphQL spec.
§Example
use apollo_encoder::{Argument, Directive, EnumValue, EnumDefinition, Value};
let mut enum_ty_1 = EnumValue::new("CAT_TREE".to_string());
enum_ty_1.description("Top bunk of a cat tree.".to_string());
let enum_ty_2 = EnumValue::new("BED".to_string());
let mut deprecated_directive = Directive::new(String::from("deprecated"));
deprecated_directive.arg(Argument::new(String::from("reason"), Value::String(String::from("Box was recycled."))));
let mut enum_ty_3 = EnumValue::new("CARDBOARD_BOX".to_string());
enum_ty_3.directive(deprecated_directive);
let mut enum_ = EnumDefinition::new("NapSpots".to_string());
enum_.description("Favourite cat nap spots.".to_string());
enum_.value(enum_ty_1);
enum_.value(enum_ty_2);
enum_.value(enum_ty_3);
assert_eq!(
enum_.to_string(),
r#""Favourite cat nap spots."
enum NapSpots {
"Top bunk of a cat tree."
CAT_TREE
BED
CARDBOARD_BOX @deprecated(reason: "Box was recycled.")
}
"#
);
Implementations§
Source§impl EnumDefinition
impl EnumDefinition
Sourcepub fn description(&mut self, description: String)
pub fn description(&mut self, description: String)
Set the Enum Definition’s description.
Trait Implementations§
Source§impl Clone for EnumDefinition
impl Clone for EnumDefinition
Source§fn clone(&self) -> EnumDefinition
fn clone(&self) -> EnumDefinition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for EnumDefinition
impl Debug for EnumDefinition
Source§impl Display for EnumDefinition
impl Display for EnumDefinition
Source§impl PartialEq for EnumDefinition
impl PartialEq for EnumDefinition
Source§impl TryFrom<EnumTypeDefinition> for EnumDefinition
impl TryFrom<EnumTypeDefinition> for EnumDefinition
Source§fn try_from(node: EnumTypeDefinition) -> Result<Self, Self::Error>
fn try_from(node: EnumTypeDefinition) -> 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<EnumTypeExtension> for EnumDefinition
impl TryFrom<EnumTypeExtension> for EnumDefinition
Source§fn try_from(node: EnumTypeExtension) -> Result<Self, Self::Error>
fn try_from(node: EnumTypeExtension) -> 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.