From eb0ca68b0474c9509ee7f7d31ea0d505cb8fc7f7 Mon Sep 17 00:00:00 2001 From: Stephen Wicklund Date: Wed, 6 Apr 2022 20:21:02 -0700 Subject: [PATCH] Added instructions for returning errors from subscription resolvers ^Title. The example code in my comment is fairly long, so I just linked to it rather than filling the page with it (also because my solution for changing the error-type within the resolver is probably more verbose than needed). --- docs/en/src/error_handling.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/en/src/error_handling.md b/docs/en/src/error_handling.md index 29804042..6cd4080d 100644 --- a/docs/en/src/error_handling.md +++ b/docs/en/src/error_handling.md @@ -25,3 +25,12 @@ impl Query { } } ``` + +#### Errors in subscriptions + +Errors can be returned from subscription resolvers as well, using a return type of the form: +```rust +async fn my_subscription_resolver(&self) -> impl Stream> { ... } +``` + +Note however that the `MyError` struct must have `Clone` implemented, due to the restrictions placed by the `Subscription` macro. One way to accomplish this is by creating a custom error type, with `#[derive(Clone)]`, as [seen here](https://github.com/async-graphql/async-graphql/issues/845#issuecomment-1090933464).