Implement GraphQL enum to Value conversion. #617
This commit is contained in:
parent
d3e14ae613
commit
d724507458
|
@ -167,6 +167,12 @@ pub fn generate(enum_args: &args::Enum) -> GeneratorResult<TokenStream> {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<#ident> for #crate_name::Value {
|
||||
fn from(value: #ident) -> #crate_name::Value {
|
||||
#crate_name::resolver_utils::enum_value(value)
|
||||
}
|
||||
}
|
||||
|
||||
#remote_conversion
|
||||
};
|
||||
Ok(expanded.into())
|
||||
|
|
|
@ -2,6 +2,13 @@ use async_graphql::*;
|
|||
|
||||
#[tokio::test]
|
||||
pub async fn test_error_extensions() {
|
||||
#[derive(Enum, Eq, PartialEq, Copy, Clone)]
|
||||
enum MyEnum {
|
||||
Create,
|
||||
Delete,
|
||||
Update,
|
||||
}
|
||||
|
||||
struct Query;
|
||||
|
||||
#[Object]
|
||||
|
@ -10,6 +17,7 @@ pub async fn test_error_extensions() {
|
|||
Err("my error".extend_with(|err, e| {
|
||||
e.set("msg", err.to_string());
|
||||
e.set("code", 100);
|
||||
e.set("action", MyEnum::Create)
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -40,7 +48,8 @@ pub async fn test_error_extensions() {
|
|||
"path": ["extendErr"],
|
||||
"extensions": {
|
||||
"msg": "my error",
|
||||
"code": 100
|
||||
"code": 100,
|
||||
"action": "CREATE",
|
||||
}
|
||||
}]
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user