#[Subscription]
Define a GraphQL subscription
See also the Book.
The field function is a synchronization function that performs filtering. When true is returned, the message is pushed to the client.
The second parameter is the type of the field.
Starting with the third parameter is one or more filtering conditions, The filter condition is the parameter of the field.
The filter function should be synchronous.
Attribute | description | Type | Optional |
name | Object name | string | Y |
desc | Object description | string | Y |
Attribute | description | Type | Optional |
name | Field name | string | Y |
desc | Field description | string | Y |
deprecation | Field deprecation reason | string | Y |
guard | Field of guard | Guard | Y |
feature | It's like a #[cfg(feature = "foo")] attribute but instead of not compiling this field it will just return a proper FieldError to tell you this feature is not enabled | string ("feature1,feature2") | Y |
Attribute | description | Type | Optional |
name | Argument name | string | Y |
desc | Argument 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 |
use async_graphql::*;
use futures::{Stream, StreamExt};
struct SubscriptionRoot;
#[Subscription]
impl SubscriptionRoot {
async fn value(&self, condition: i32) -> impl Stream<Item = i32> {
futures::stream::iter(0..condition)
}
}