WIP subscription support, will require switching webserver

This commit is contained in:
Bill Thiede 2025-03-08 07:51:36 -08:00
parent 638d55a36c
commit d7217d1b3c
2 changed files with 20 additions and 6 deletions

View File

@ -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<String> {
content::RawHtml(GraphiQLSource::build().endpoint("/api/graphql").finish())
content::RawHtml(
GraphiQLSource::build()
.endpoint("/api/graphql")
.subscription_endpoint("/api/graphql")
.finish(),
)
}
#[rocket::get("/graphql?<query..>")]
@ -222,7 +227,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
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());

View File

@ -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<QueryRoot, Mutation, EmptySubscription>;
pub struct Subscription;
#[async_graphql::Subscription]
impl Subscription {
async fn values(&self, ctx: &Context<'_>) -> Result<impl Stream<Item = usize>, Error> {
Ok(stream::iter(0..10))
}
}
pub type GraphqlSchema = Schema<QueryRoot, Mutation, Subscription>;