Skip to content

Commit

Permalink
feat(graphql): add raw to exceptions on QueryResult
Browse files Browse the repository at this point in the history
  • Loading branch information
maironLucasSlz committed Nov 28, 2022
1 parent 32f95c5 commit 1e9581e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/graphql/lib/src/exceptions/exceptions_next.dart
Expand Up @@ -165,9 +165,12 @@ class OperationException implements Exception {

StackTrace? originalStackTrace;

List<dynamic>? raw;

OperationException({
this.linkException,
this.originalStackTrace,
this.raw,
Iterable<GraphQLError> graphqlErrors = const [],
}) : this.graphqlErrors = graphqlErrors.toList();

Expand All @@ -188,13 +191,15 @@ class OperationException implements Exception {
OperationException? coalesceErrors({
List<GraphQLError>? graphqlErrors,
LinkException? linkException,
List<dynamic>? raw,
OperationException? exception,
}) {
if (exception != null ||
linkException != null ||
(graphqlErrors != null && graphqlErrors.isNotEmpty)) {
return OperationException(
linkException: linkException ?? exception?.linkException,
raw: raw,
graphqlErrors: [
if (graphqlErrors != null) ...graphqlErrors,
if (exception?.graphqlErrors != null) ...exception!.graphqlErrors
Expand Down
8 changes: 7 additions & 1 deletion packages/graphql/lib/src/utilities/response.dart
Expand Up @@ -9,6 +9,7 @@ QueryResult<TParsed> mapFetchResultToQueryResult<TParsed>(
}) {
List<GraphQLError>? errors;
Map<String, dynamic>? data;
Map<String, dynamic>? raw;

// check if there are errors and apply the error policy if so
// in a nutshell: `ignore` swallows errors, `none` swallows data
Expand All @@ -34,11 +35,16 @@ QueryResult<TParsed> mapFetchResultToQueryResult<TParsed>(
data = response.data;
}

raw = response.response;

return QueryResult(
options: options,
data: data,
context: response.context,
source: source,
exception: coalesceErrors(graphqlErrors: errors),
exception: coalesceErrors(
graphqlErrors: errors,
raw: raw['errors'] as List<dynamic>?,
),
);
}

0 comments on commit 1e9581e

Please sign in to comment.