Struct apollo_encoder::EnumDefinition
source · 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<EnumDefinition> for EnumDefinition
impl PartialEq<EnumDefinition> for EnumDefinition
source§fn eq(&self, other: &EnumDefinition) -> bool
fn eq(&self, other: &EnumDefinition) -> bool
self
and other
values to be equal, and is used
by ==
.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.