async-graphql/src/model/enum_value.rs

30 lines
905 B
Rust
Raw Normal View History

2020-03-05 06:23:55 +00:00
use crate::{registry, Context};
2020-03-02 11:25:21 +00:00
use async_graphql_derive::Object;
2020-03-03 11:15:18 +00:00
pub struct __EnumValue<'a> {
pub registry: &'a registry::Registry,
pub value: &'a registry::EnumValue,
}
2020-03-02 11:25:21 +00:00
2020-03-05 06:23:55 +00:00
#[Object(
internal,
desc = "One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string."
)]
impl<'a> __EnumValue<'a> {
async fn name(&self, _: &Context<'_>) -> String {
2020-03-05 06:23:55 +00:00
self.value.name.to_string()
2020-03-02 11:25:21 +00:00
}
async fn description(&self, _: &Context<'_>) -> Option<String> {
2020-03-05 06:23:55 +00:00
self.value.description.map(|s| s.to_string())
2020-03-02 11:25:21 +00:00
}
async fn is_deprecated(&self, _: &Context<'_>) -> bool {
2020-03-05 06:23:55 +00:00
self.value.deprecation.is_some()
2020-03-02 11:25:21 +00:00
}
async fn deprecation_reason(&self, _: &Context<'_>) -> Option<String> {
2020-03-05 06:23:55 +00:00
self.value.deprecation.map(|s| s.to_string())
2020-03-02 11:25:21 +00:00
}
}