From 1e9581eff0d6edd05e60bb176a772e5db8049b51 Mon Sep 17 00:00:00 2001 From: Mairon Lucas Date: Thu, 6 Oct 2022 17:05:59 -0300 Subject: [PATCH] feat(graphql): add raw to exceptions on QueryResult --- packages/graphql/lib/src/exceptions/exceptions_next.dart | 5 +++++ packages/graphql/lib/src/utilities/response.dart | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/graphql/lib/src/exceptions/exceptions_next.dart b/packages/graphql/lib/src/exceptions/exceptions_next.dart index 9389c6959..78420fa7e 100644 --- a/packages/graphql/lib/src/exceptions/exceptions_next.dart +++ b/packages/graphql/lib/src/exceptions/exceptions_next.dart @@ -165,9 +165,12 @@ class OperationException implements Exception { StackTrace? originalStackTrace; + List? raw; + OperationException({ this.linkException, this.originalStackTrace, + this.raw, Iterable graphqlErrors = const [], }) : this.graphqlErrors = graphqlErrors.toList(); @@ -188,6 +191,7 @@ class OperationException implements Exception { OperationException? coalesceErrors({ List? graphqlErrors, LinkException? linkException, + List? raw, OperationException? exception, }) { if (exception != null || @@ -195,6 +199,7 @@ OperationException? coalesceErrors({ (graphqlErrors != null && graphqlErrors.isNotEmpty)) { return OperationException( linkException: linkException ?? exception?.linkException, + raw: raw, graphqlErrors: [ if (graphqlErrors != null) ...graphqlErrors, if (exception?.graphqlErrors != null) ...exception!.graphqlErrors diff --git a/packages/graphql/lib/src/utilities/response.dart b/packages/graphql/lib/src/utilities/response.dart index a332545d6..1d7d7b50d 100644 --- a/packages/graphql/lib/src/utilities/response.dart +++ b/packages/graphql/lib/src/utilities/response.dart @@ -9,6 +9,7 @@ QueryResult mapFetchResultToQueryResult( }) { List? errors; Map? data; + Map? raw; // check if there are errors and apply the error policy if so // in a nutshell: `ignore` swallows errors, `none` swallows data @@ -34,11 +35,16 @@ QueryResult mapFetchResultToQueryResult( 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?, + ), ); }