New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are subscription updates supported? #37
Comments
If you look a this line you can see that the plugin in fact reads and emits the stream items asynchronously so yes subscriptions are fully supported. What you meant is that the handler returns only once, but it returns a stream! The example in this repo is maybe a bit misleading in this regard, you would never construct a stream from a vec in real code. But you can construct a stream from a use async_stream::wrappers:: ReceiverStream;
use tokio::time::{sleep, Duration};
#[graphql_subscription(context = GraphQLContext)]
impl Subscription {
async fn hello_world() -> StringStream {
let (tx,rx) = tokio::mpsc::channel(16);
tokio::spawn(async move {
for i in 0..10 {
if let Err(_) = tx.send(i).await {
println!("receiver dropped");
return;
}
sleep(Duration::from_millis(250)).await;
}
});
Box::pin(ReceiverStream::new(rx))
}
} The above snippet will (hopefully) produce 10 subscription updates spaced 250ms apart to make the effect more noticeable. |
Okay I see it was a problem with my subscription stream logic. I got it working now, thanks for pointing me in the right direction. Great library btw. |
First time a subscription is executed on the frontend it returns data and works fine but I'm unable to get any updates.
Reading the library code it looks like data from subscription handler stream is only read and emitted once after which the function returns, initially I thought that I must make my streams to never return
None
but instead that lead to the whole program freezing. I'm pretty new to rust and juniper but to me it seems like these currently implemented "subscriptions" are really more one-off events and updates are not supported. Is this correct?The text was updated successfully, but these errors were encountered: