Add the skip
attribute to the InputObject fields.
This commit is contained in:
parent
004ff93557
commit
fe24247c9d
|
@ -238,6 +238,8 @@ pub struct InputObjectField {
|
|||
#[darling(default)]
|
||||
pub flatten: bool,
|
||||
#[darling(default)]
|
||||
pub skip: bool,
|
||||
#[darling(default)]
|
||||
pub visible: Option<Visible>,
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,14 @@ pub fn generate(object_args: &args::InputObject) -> GeneratorResult<TokenStream>
|
|||
.rename(ident.unraw().to_string(), RenameTarget::Field)
|
||||
});
|
||||
|
||||
if field.skip {
|
||||
get_fields.push(quote! {
|
||||
let #ident: #ty = ::std::default::Default::default();
|
||||
});
|
||||
fields.push(ident);
|
||||
continue;
|
||||
}
|
||||
|
||||
if field.flatten {
|
||||
flatten_fields.push((ident, ty));
|
||||
|
||||
|
|
|
@ -495,8 +495,9 @@ pub use async_graphql_derive::Enum;
|
|||
/// | default_with | Expression to generate default value | code string | Y |
|
||||
/// | validator | Input value validator | [`InputValueValidator`](validators/trait.InputValueValidator.html) | Y |
|
||||
/// | flatten | Similar to serde (flatten) | boolean | Y |
|
||||
/// | visible | If `false`, it will not be displayed in introspection. *[See also the Book](https://async-graphql.github.io/async-graphql/en/visibility.html).* | bool | Y |
|
||||
/// | visible | Call the specified function. If the return value is `false`, it will not be displayed in introspection. | string | Y |
|
||||
/// | skip | Skip this field, use `Default::default` to get a default value for this field. | bool | Y |
|
||||
/// | visible | If `false`, it will not be displayed in introspection. *[See also the Book](https://async-graphql.github.io/async-graphql/en/visibility.html).* | bool | Y |
|
||||
/// | visible | Call the specified function. If the return value is `false`, it will not be displayed in introspection. | string | Y |
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
|
@ -287,3 +287,34 @@ pub async fn test_inputobject_flatten_multiple() {
|
|||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
pub async fn test_input_object_skip_field() {
|
||||
#[derive(InputObject)]
|
||||
struct MyInput2 {
|
||||
a: i32,
|
||||
#[graphql(skip)]
|
||||
b: i32,
|
||||
}
|
||||
|
||||
struct Root;
|
||||
|
||||
#[Object]
|
||||
impl Root {
|
||||
async fn a(&self, input: MyInput2) -> i32 {
|
||||
assert_eq!(input.b, i32::default());
|
||||
input.a
|
||||
}
|
||||
}
|
||||
|
||||
let schema = Schema::new(Root, EmptyMutation, EmptySubscription);
|
||||
let query = r#"{
|
||||
a(input:{a: 777})
|
||||
}"#;
|
||||
assert_eq!(
|
||||
schema.execute(query).await.into_result().unwrap().data,
|
||||
value!({
|
||||
"a": 777
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user