Fixed #attribute not working on the InputObject fields.

This commit is contained in:
sunli 2020-04-08 12:02:48 +08:00
parent a813ce72a3
commit 03e1604f0b
2 changed files with 24 additions and 0 deletions

View File

@ -20,7 +20,13 @@ pub fn generate(object_args: &args::InputObject, input: &DeriveInput) -> Result<
let vis = &field.vis;
let ty = &field.ty;
let ident = &field.ident;
let attrs = field
.attrs
.iter()
.filter(|attr| !attr.path.is_ident("field"))
.collect::<Vec<_>>();
struct_fields.push(quote! {
#(#attrs)*
#vis #ident: #ty
});
}

View File

@ -93,3 +93,21 @@ pub async fn test_input_object_default_value() {
})
);
}
#[async_std::test]
pub async fn test_inputobject_derive_and_item_attributes() {
use serde::Deserialize;
#[async_graphql::InputObject]
#[derive(Deserialize, PartialEq, Debug)]
struct MyInputObject {
#[field]
#[serde(alias = "other")]
real: i32,
}
assert_eq!(
serde_json::from_str::<MyInputObject>(r#"{ "other" : 100 }"#).unwrap(),
MyInputObject { real: 100 }
);
}