[−][src]Derive Macro async_graphql::GQLInputObject
#[derive(GQLInputObject)] { // Attributes available to this derive: #[field] #[graphql] }
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 |
flatten | Similar to serde (flatten) | boolean | Y |
Examples
use async_graphql::*; #[derive(GQLInputObject)] struct MyInputObject { a: i32, #[field(default = 10)] b: i32, } struct QueryRoot; #[GQLObject] 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.into_result().unwrap().data; assert_eq!(res, serde_json::json!({ "value1": 27, "value2": 90 })); });