Skip to content

Commit 1e9581e

Browse files
feat(graphql): add raw to exceptions on QueryResult
1 parent 32f95c5 commit 1e9581e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/graphql/lib/src/exceptions/exceptions_next.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,12 @@ class OperationException implements Exception {
165165

166166
StackTrace? originalStackTrace;
167167

168+
List<dynamic>? raw;
169+
168170
OperationException({
169171
this.linkException,
170172
this.originalStackTrace,
173+
this.raw,
171174
Iterable<GraphQLError> graphqlErrors = const [],
172175
}) : this.graphqlErrors = graphqlErrors.toList();
173176

@@ -188,13 +191,15 @@ class OperationException implements Exception {
188191
OperationException? coalesceErrors({
189192
List<GraphQLError>? graphqlErrors,
190193
LinkException? linkException,
194+
List<dynamic>? raw,
191195
OperationException? exception,
192196
}) {
193197
if (exception != null ||
194198
linkException != null ||
195199
(graphqlErrors != null && graphqlErrors.isNotEmpty)) {
196200
return OperationException(
197201
linkException: linkException ?? exception?.linkException,
202+
raw: raw,
198203
graphqlErrors: [
199204
if (graphqlErrors != null) ...graphqlErrors,
200205
if (exception?.graphqlErrors != null) ...exception!.graphqlErrors

packages/graphql/lib/src/utilities/response.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ QueryResult<TParsed> mapFetchResultToQueryResult<TParsed>(
99
}) {
1010
List<GraphQLError>? errors;
1111
Map<String, dynamic>? data;
12+
Map<String, dynamic>? raw;
1213

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

38+
raw = response.response;
39+
3740
return QueryResult(
3841
options: options,
3942
data: data,
4043
context: response.context,
4144
source: source,
42-
exception: coalesceErrors(graphqlErrors: errors),
45+
exception: coalesceErrors(
46+
graphqlErrors: errors,
47+
raw: raw['errors'] as List<dynamic>?,
48+
),
4349
);
4450
}

0 commit comments

Comments
 (0)