diff --git a/server/src/bin/letterbox-server.rs b/server/src/bin/letterbox-server.rs index 037a0fd..e0a3999 100644 --- a/server/src/bin/letterbox-server.rs +++ b/server/src/bin/letterbox-server.rs @@ -14,7 +14,7 @@ use letterbox_server::tantivy::TantivyConnection; use letterbox_server::{ config::Config, error::ServerError, - graphql::{Attachment, GraphqlSchema, Mutation, QueryRoot}, + graphql::{Attachment, GraphqlSchema, Mutation, QueryRoot, Subscription}, nm::{attachment_bytes, cid_attachment_bytes}, }; use rocket::{ @@ -159,7 +159,12 @@ async fn original( #[rocket::get("/")] fn graphiql() -> content::RawHtml { - content::RawHtml(GraphiQLSource::build().endpoint("/api/graphql").finish()) + content::RawHtml( + GraphiQLSource::build() + .endpoint("/api/graphql") + .subscription_endpoint("/api/graphql") + .finish(), + ) } #[rocket::get("/graphql?")] @@ -222,7 +227,7 @@ async fn main() -> Result<(), Box> { let tantivy_conn = TantivyConnection::new(&config.newsreader_tantivy_db_path)?; let cacher = FilesystemCacher::new(&config.slurp_cache_path)?; - let schema = Schema::build(QueryRoot, Mutation, EmptySubscription) + let schema = Schema::build(QueryRoot, Mutation, Subscription) .data(Notmuch::default()) .data(cacher) .data(pool.clone()); diff --git a/server/src/graphql.rs b/server/src/graphql.rs index 2d548c7..ee603a0 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -2,10 +2,11 @@ use std::{fmt, str::FromStr}; use async_graphql::{ connection::{self, Connection, Edge, OpaqueCursor}, - Context, EmptySubscription, Enum, Error, FieldResult, InputObject, Object, Schema, - SimpleObject, Union, + futures_util::{Stream, StreamExt}, + Context, Enum, Error, FieldResult, InputObject, Object, Schema, SimpleObject, Union, }; use cacher::FilesystemCacher; +use futures::stream; use letterbox_notmuch::Notmuch; use log::info; use serde::{Deserialize, Serialize}; @@ -667,4 +668,12 @@ impl Mutation { } } -pub type GraphqlSchema = Schema; +pub struct Subscription; +#[async_graphql::Subscription] +impl Subscription { + async fn values(&self, ctx: &Context<'_>) -> Result, Error> { + Ok(stream::iter(0..10)) + } +} + +pub type GraphqlSchema = Schema;