#[Subscription]
Expand description

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 attributes

AttributedescriptionTypeOptional
nameObject namestringY
name_typeIf true, the object name will be specified from async_graphql::TypeName traitboolY
rename_fieldsRename all the fields according to the given case convention. The possible values are “lowercase”, “UPPERCASE”, “PascalCase”, “camelCase”, “snake_case”, “SCREAMING_SNAKE_CASE”.stringY
rename_argsRename all the arguments according to the given case convention. The possible values are “lowercase”, “UPPERCASE”, “PascalCase”, “camelCase”, “snake_case”, “SCREAMING_SNAKE_CASE”.stringY
extendsAdd fields to an entity that’s defined in another serviceboolY
visibleIf false, it will not be displayed in introspection. See also the Book.boolY
visibleCall the specified function. If the return value is false, it will not be displayed in introspection.stringY
use_type_descriptionSpecifies that the description of the type is on the type declaration. Description(derive.Description.html)boolY
guardField of guard See also the BookstringY

Field attributes

AttributedescriptionTypeOptional
nameField namestringY
deprecationField deprecatedboolY
deprecationField deprecation reasonstringY
guardField of guard See also the BookstringY
visibleIf false, it will not be displayed in introspection. See also the Book.boolY
visibleCall the specified function. If the return value is false, it will not be displayed in introspection.stringY
complexityCustom field complexity. See also the Book.boolY
complexityCustom field complexity.stringY
secretMark this field as a secret, it will not output the actual value in the log.boolY

Field argument attributes

AttributedescriptionTypeOptional
nameArgument namestringY
descArgument descriptionstringY
defaultUse Default::default for default valuenoneY
defaultArgument default valueliteralY
default_withExpression to generate default valuecode stringY
validatorInput value validator See also the BookobjectY
visibleIf false, it will not be displayed in introspection. See also the Book.boolY
visibleCall the specified function. If the return value is false, it will not be displayed in introspection.stringY
process_withUpon successful parsing, invokes specified function. Its signature must be fn(&mut T).code pathY

Examples

use async_graphql::*;
use futures_util::stream::{Stream, StreamExt};

struct Subscription;

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