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).
This commit is contained in:
Stephen Wicklund 2022-04-06 20:21:02 -07:00 committed by GitHub
parent c8c397c770
commit 5efb65c448
1 changed files with 9 additions and 0 deletions

View File

@ -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<Item = Result<MyItem, MyError>> { ... }
```
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).