[][src]Attribute Macro async_graphql::GQLSubscription

#[GQLSubscription]

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.

Macro parameters

AttributedescriptionTypeOptional
nameObject namestringY
descObject descriptionstringY

Field parameters

AttributedescriptionTypeOptional
nameField namestringY
descField descriptionstringY
deprecationField deprecation reasonstringY
guardField of guardGuardY
featureIt'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 enabledstring ("feature1,feature2")Y

Field argument parameters

AttributedescriptionTypeOptional
nameArgument namestringY
descArgument descriptionstringY
defaultUse Default::default for default valuenoneY
defaultArgument default valueliteralY
default_withExpression to generate default valuecode stringY
validatorInput value validatorInputValueValidatorY

Examples

use async_graphql::*;
use futures::{Stream, StreamExt};

struct SubscriptionRoot;

#[GQLSubscription]
impl SubscriptionRoot {
    async fn value(&self, condition: i32) -> impl Stream<Item = i32> {
        // Returns the number from 0 to `condition`.
        futures::stream::iter(0..condition)
    }
}