WIP subscription support, will require switching webserver
This commit is contained in:
parent
638d55a36c
commit
d7217d1b3c
@ -14,7 +14,7 @@ use letterbox_server::tantivy::TantivyConnection;
|
|||||||
use letterbox_server::{
|
use letterbox_server::{
|
||||||
config::Config,
|
config::Config,
|
||||||
error::ServerError,
|
error::ServerError,
|
||||||
graphql::{Attachment, GraphqlSchema, Mutation, QueryRoot},
|
graphql::{Attachment, GraphqlSchema, Mutation, QueryRoot, Subscription},
|
||||||
nm::{attachment_bytes, cid_attachment_bytes},
|
nm::{attachment_bytes, cid_attachment_bytes},
|
||||||
};
|
};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
@ -159,7 +159,12 @@ async fn original(
|
|||||||
|
|
||||||
#[rocket::get("/")]
|
#[rocket::get("/")]
|
||||||
fn graphiql() -> content::RawHtml<String> {
|
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..>")]
|
#[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 tantivy_conn = TantivyConnection::new(&config.newsreader_tantivy_db_path)?;
|
||||||
|
|
||||||
let cacher = FilesystemCacher::new(&config.slurp_cache_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(Notmuch::default())
|
||||||
.data(cacher)
|
.data(cacher)
|
||||||
.data(pool.clone());
|
.data(pool.clone());
|
||||||
|
|||||||
@ -2,10 +2,11 @@ use std::{fmt, str::FromStr};
|
|||||||
|
|
||||||
use async_graphql::{
|
use async_graphql::{
|
||||||
connection::{self, Connection, Edge, OpaqueCursor},
|
connection::{self, Connection, Edge, OpaqueCursor},
|
||||||
Context, EmptySubscription, Enum, Error, FieldResult, InputObject, Object, Schema,
|
futures_util::{Stream, StreamExt},
|
||||||
SimpleObject, Union,
|
Context, Enum, Error, FieldResult, InputObject, Object, Schema, SimpleObject, Union,
|
||||||
};
|
};
|
||||||
use cacher::FilesystemCacher;
|
use cacher::FilesystemCacher;
|
||||||
|
use futures::stream;
|
||||||
use letterbox_notmuch::Notmuch;
|
use letterbox_notmuch::Notmuch;
|
||||||
use log::info;
|
use log::info;
|
||||||
use serde::{Deserialize, Serialize};
|
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>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user