[−][src]Function async_graphql_warp::graphql_subscription
pub fn graphql_subscription<Query, Mutation, Subscription>(
schema: Schema<Query, Mutation, Subscription>
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone where
Query: ObjectType + Sync + Send + 'static,
Mutation: ObjectType + Sync + Send + 'static,
Subscription: SubscriptionType + Send + Sync + 'static,
GraphQL subscription filter
Examples
use async_graphql::*; use async_graphql_warp::*; use warp::Filter; use futures::{Stream, StreamExt}; use std::time::Duration; struct QueryRoot; #[Object] impl QueryRoot {} struct SubscriptionRoot; #[Subscription] impl SubscriptionRoot { async fn tick(&self) -> impl Stream<Item = String> { tokio::time::interval(Duration::from_secs(1)).map(|n| format!("{}", n.elapsed().as_secs_f32())) } } #[tokio::main] async fn main() { let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot); let filter = async_graphql_warp::graphql_subscription(schema) .or(warp::any().map(|| "Hello, World!")); warp::serve(filter).run(([0, 0, 0, 0], 8000)).await; }