Skip to content

Commit eca049a

Browse files
authored
Implement IntoFieldError for Infallible (#796)
Makes it possible to use `Result<T, Infallible>` as your return type from resolvers, which can be handy sometimes.
1 parent f6ec735 commit eca049a

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct Query;
2+
3+
#[juniper::graphql_object]
4+
impl Query {
5+
fn ping() -> Result<bool, std::convert::Infallible> {
6+
Ok(false)
7+
}
8+
}

integration_tests/juniper_tests/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ mod custom_scalar;
77
#[cfg(test)]
88
mod explicit_null;
99
#[cfg(test)]
10+
mod infallible_as_field_error;
11+
#[cfg(test)]
1012
mod issue_371;
1113
#[cfg(test)]
1214
mod issue_398;

juniper/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
- Added support for distinguishing between between implicit and explicit null. ([#795](https://github.com/graphql-rust/juniper/pull/795))
3939

40+
41+
- Implement `IntoFieldError` for `std::convert::Infallible`. ([#796](https://github.com/graphql-rust/juniper/pull/796))
42+
4043
## Fixes
4144

4245
- Massively improved the `#[graphql_union]` proc macro. ([#666](https://github.com/graphql-rust/juniper/pull/666)):

juniper/src/executor/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ impl<S> IntoFieldError<S> for FieldError<S> {
246246
}
247247
}
248248

249+
impl<S> IntoFieldError<S> for std::convert::Infallible {
250+
fn into_field_error(self) -> FieldError<S> {
251+
match self {}
252+
}
253+
}
254+
249255
#[doc(hidden)]
250256
pub trait IntoResolvable<'a, S, T, C>
251257
where

0 commit comments

Comments
 (0)