diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 5a969a99b..bef9b3b5f 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -43,6 +43,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi - `jiff::tz::TimeZone` as `TimeZoneOrUtcOffset` and `TimeZone` scalars. - `jiff::tz::Offset` as `UtcOffset` scalar. - `jiff::Span` as `Duration` scalar. +- `http::GraphQLResponse::into_result()` method. ([#1293]) ### Changed @@ -62,6 +63,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi [#1281]: /../../pull/1281 [#1284]: /../../pull/1284 [#1287]: /../../issues/1287 +[#1293]: /../../pull/1293 [#1311]: /../../pull/1311 [#1316]: /../../pull/1316 [#1318]: /../../pull/1318 diff --git a/juniper/src/http/mod.rs b/juniper/src/http/mod.rs index f89ffab80..3e395169f 100644 --- a/juniper/src/http/mod.rs +++ b/juniper/src/http/mod.rs @@ -171,20 +171,28 @@ impl GraphQLResponse where S: ScalarValue, { - /// Constructs new `GraphQLResponse` using the given result + /// Constructs a new [`GraphQLResponse`] from the provided execution [`Result`]. + #[must_use] pub fn from_result(r: Result<(Value, Vec>), GraphQLError>) -> Self { Self(r) } - /// Constructs an error response outside of the normal execution flow + /// Unwraps this [`GraphQLResponse`] into its underlying execution [`Result`]. + pub fn into_result(self) -> Result<(Value, Vec>), GraphQLError> { + self.0 + } + + /// Constructs an error [`GraphQLResponse`] outside the normal execution flow. + #[must_use] pub fn error(error: FieldError) -> Self { - GraphQLResponse(Ok((Value::null(), vec![ExecutionError::at_origin(error)]))) + Self(Ok((Value::null(), vec![ExecutionError::at_origin(error)]))) } - /// Was the request successful or not? + /// Indicates whether this [`GraphQLResponse`] contains a successful execution [`Result`]. /// - /// Note that there still might be errors in the response even though it's - /// considered OK. This is by design in GraphQL. + /// **NOTE**: There still might be errors in the response even though it's considered OK. + /// This is by design in GraphQL. + #[must_use] pub fn is_ok(&self) -> bool { self.0.is_ok() }