Struct apollo_encoder::EnumValue
source · pub struct EnumValue { /* private fields */ }
Expand description
The EnumValue type represents one of possible values of an enum.
EnumValueDefinition: Description? EnumValue Directives?
Detailed documentation can be found in GraphQL spec.
Example
use apollo_encoder::{Argument, Directive, EnumValue, Value};
let mut enum_ty = EnumValue::new("CARDBOARD_BOX".to_string());
enum_ty.description("Box nap spot.".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.",
)),
));
enum_ty.directive(deprecated_directive);
assert_eq!(
enum_ty.to_string(),
r#" "Box nap spot."
CARDBOARD_BOX @deprecated(reason: "Box was recycled.")"#
);
Implementations§
Trait Implementations§
source§impl TryFrom<EnumValueDefinition> for EnumValue
impl TryFrom<EnumValueDefinition> for EnumValue
source§fn try_from(node: EnumValueDefinition) -> Result<Self, Self::Error>
fn try_from(node: EnumValueDefinition) -> 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.