From 5102a7ccd2973549d0775ee2fc499f0fb6add2d1 Mon Sep 17 00:00:00 2001 From: Ryoga Kitagawa Date: Tue, 12 Nov 2024 13:46:48 +0900 Subject: [PATCH 1/3] Expose inner value of GraphQLResponse. --- juniper/src/http/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juniper/src/http/mod.rs b/juniper/src/http/mod.rs index 38ef764f2..bb70e41d2 100644 --- a/juniper/src/http/mod.rs +++ b/juniper/src/http/mod.rs @@ -165,7 +165,7 @@ where /// whether to send a 200 or 400 HTTP status code. #[derive(Clone, Debug, PartialEq)] pub struct GraphQLResponse( - Result<(Value, Vec>), GraphQLError>, + pub Result<(Value, Vec>), GraphQLError>, ); impl GraphQLResponse From c41db7bc7be234d2708439f30b5f9db965518f4a Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 9 May 2025 18:29:51 +0200 Subject: [PATCH 2/3] Upd code --- juniper/src/http/mod.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/juniper/src/http/mod.rs b/juniper/src/http/mod.rs index 3a4817104..3e395169f 100644 --- a/juniper/src/http/mod.rs +++ b/juniper/src/http/mod.rs @@ -164,27 +164,35 @@ where /// whether to send a 200 or 400 HTTP status code. #[derive(Clone, Debug, PartialEq)] pub struct GraphQLResponse( - pub Result<(Value, Vec>), GraphQLError>, + Result<(Value, Vec>), GraphQLError>, ); 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() } From 2ad7fd86d13283f0255d2db5bf5ee8af4e3c8f02 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 9 May 2025 18:34:23 +0200 Subject: [PATCH 3/3] Mention in CHANGELOG --- juniper/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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