Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
20 changes: 14 additions & 6 deletions juniper/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,28 @@ impl<S> GraphQLResponse<S>
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<S>, Vec<ExecutionError<S>>), 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<S>, Vec<ExecutionError<S>>), GraphQLError> {
self.0
}

/// Constructs an error [`GraphQLResponse`] outside the normal execution flow.
#[must_use]
pub fn error(error: FieldError<S>) -> 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()
}
Expand Down