2020-03-03 11:15:18 +00:00
use crate ::{ registry , Context , Result } ;
2020-03-02 11:25:21 +00:00
use async_graphql_derive ::Object ;
#[ 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. " ,
field ( name = " name " , type = " String " , owned ) ,
field ( name = " description " , type = " Option<String> " , owned ) ,
field ( name = " isDeprecated " , type = " bool " , owned ) ,
field ( name = " deprecationReason " , type = " Option<String> " , owned )
) ]
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
#[ async_trait::async_trait ]
2020-03-03 11:15:18 +00:00
impl < ' a > __EnumValueFields for __EnumValue < ' a > {
2020-03-03 03:48:00 +00:00
async fn name ( & self , _ : & Context < '_ > ) -> Result < String > {
2020-03-03 11:15:18 +00:00
Ok ( self . value . name . to_string ( ) )
2020-03-02 11:25:21 +00:00
}
2020-03-03 03:48:00 +00:00
async fn description ( & self , _ : & Context < '_ > ) -> Result < Option < String > > {
2020-03-03 11:15:18 +00:00
Ok ( self . value . description . map ( | s | s . to_string ( ) ) )
2020-03-02 11:25:21 +00:00
}
2020-03-03 03:48:00 +00:00
async fn is_deprecated ( & self , _ : & Context < '_ > ) -> Result < bool > {
2020-03-03 11:15:18 +00:00
Ok ( self . value . deprecation . is_some ( ) )
2020-03-02 11:25:21 +00:00
}
2020-03-03 03:48:00 +00:00
async fn deprecation_reason ( & self , _ : & Context < '_ > ) -> Result < Option < String > > {
2020-03-03 11:15:18 +00:00
Ok ( self . value . deprecation . map ( | s | s . to_string ( ) ) )
2020-03-02 11:25:21 +00:00
}
}