[−][src]Attribute Macro async_graphql::InputObject
#[InputObject]
Define a GraphQL input object
You can also derive this.
Macro parameters
Attribute | description | Type | Optional |
---|---|---|---|
name | Object name | string | Y |
desc | Object description | string | Y |
Field parameters
Attribute | description | Type | Optional |
---|---|---|---|
name | Field name | string | Y |
desc | Field description | string | Y |
default | Use Default::default for default value | none | Y |
default | Argument default value | literal | Y |
default_with | Expression to generate default value | code string | Y |
validator | Input value validator | InputValueValidator | Y |
Examples
use async_graphql::*; #[InputObject] struct MyInputObject { a: i32, #[field(default = 10)] b: i32, } struct QueryRoot; #[Object] impl QueryRoot { #[field(desc = "value")] async fn value(&self, input: MyInputObject) -> i32 { input.a * input.b } } async_std::task::block_on(async move { let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription); let res = schema.execute(r#" { value1: value(input:{a:9, b:3}) value2: value(input:{a:9}) }"#).await.unwrap().data; assert_eq!(res, serde_json::json!({ "value1": 27, "value2": 90 })); });