Skip to content

Commit a82c2a5

Browse files
RyogaKtyranron
andauthored
Add http::GraphQLResponse::into_result() method (#1293)
Co-authored-by: Kai Ren <[email protected]>
1 parent dee3890 commit a82c2a5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

juniper/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
4343
- `jiff::tz::TimeZone` as `TimeZoneOrUtcOffset` and `TimeZone` scalars.
4444
- `jiff::tz::Offset` as `UtcOffset` scalar.
4545
- `jiff::Span` as `Duration` scalar.
46+
- `http::GraphQLResponse::into_result()` method. ([#1293])
4647

4748
### Changed
4849

@@ -62,6 +63,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
6263
[#1281]: /../../pull/1281
6364
[#1284]: /../../pull/1284
6465
[#1287]: /../../issues/1287
66+
[#1293]: /../../pull/1293
6567
[#1311]: /../../pull/1311
6668
[#1316]: /../../pull/1316
6769
[#1318]: /../../pull/1318

juniper/src/http/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,28 @@ impl<S> GraphQLResponse<S>
171171
where
172172
S: ScalarValue,
173173
{
174-
/// Constructs new `GraphQLResponse` using the given result
174+
/// Constructs a new [`GraphQLResponse`] from the provided execution [`Result`].
175+
#[must_use]
175176
pub fn from_result(r: Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError>) -> Self {
176177
Self(r)
177178
}
178179

179-
/// Constructs an error response outside of the normal execution flow
180+
/// Unwraps this [`GraphQLResponse`] into its underlying execution [`Result`].
181+
pub fn into_result(self) -> Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError> {
182+
self.0
183+
}
184+
185+
/// Constructs an error [`GraphQLResponse`] outside the normal execution flow.
186+
#[must_use]
180187
pub fn error(error: FieldError<S>) -> Self {
181-
GraphQLResponse(Ok((Value::null(), vec![ExecutionError::at_origin(error)])))
188+
Self(Ok((Value::null(), vec![ExecutionError::at_origin(error)])))
182189
}
183190

184-
/// Was the request successful or not?
191+
/// Indicates whether this [`GraphQLResponse`] contains a successful execution [`Result`].
185192
///
186-
/// Note that there still might be errors in the response even though it's
187-
/// considered OK. This is by design in GraphQL.
193+
/// **NOTE**: There still might be errors in the response even though it's considered OK.
194+
/// This is by design in GraphQL.
195+
#[must_use]
188196
pub fn is_ok(&self) -> bool {
189197
self.0.is_ok()
190198
}

0 commit comments

Comments
 (0)