Skip to content

Commit 5d16ebf

Browse files
committed
fix(graphql): Adapt code to breaking change of 'gql' dependencies
1 parent 425f648 commit 5d16ebf

File tree

8 files changed

+65
-37
lines changed

8 files changed

+65
-37
lines changed

packages/graphql/lib/src/cache/_normalizing_data_proxy.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,11 @@ abstract class NormalizingDataProxy extends GraphQLDataProxy {
144144
if (broadcast ?? true) {
145145
broadcastRequested = true;
146146
}
147-
} on PartialDataException catch (e) {
147+
} on PartialDataException catch (e, stackTrace) {
148148
if (request.validatesStructureOf(data)) {
149149
throw CacheMisconfigurationException(
150150
e,
151+
stackTrace,
151152
request: request,
152153
data: data,
153154
);
@@ -182,10 +183,11 @@ abstract class NormalizingDataProxy extends GraphQLDataProxy {
182183
if (broadcast ?? true) {
183184
broadcastRequested = true;
184185
}
185-
} on PartialDataException catch (e) {
186+
} on PartialDataException catch (e, stackTrace) {
186187
if (request.validatesStructureOf(data)) {
187188
throw CacheMisconfigurationException(
188189
e,
190+
stackTrace,
189191
fragmentRequest: request,
190192
data: data,
191193
);

packages/graphql/lib/src/core/_query_write_handling.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ typedef _IntWriteQuery = void Function(
66

77
/// Internal [PartialDataException] handling callback
88
typedef _IntPartialDataHandler = MismatchedDataStructureException Function(
9-
PartialDataException failure);
9+
PartialDataException failure, StackTrace stackTrace);
1010

1111
extension InternalQueryWriteHandling on QueryManager {
1212
/// Merges exceptions into `queryResult` and
@@ -29,10 +29,10 @@ extension InternalQueryWriteHandling on QueryManager {
2929
exception: queryResult.exception,
3030
linkException: failure,
3131
);
32-
} on PartialDataException catch (failure) {
32+
} on PartialDataException catch (failure, stackTrace) {
3333
queryResult!.exception = coalesceErrors(
3434
exception: queryResult.exception,
35-
linkException: onPartial(failure),
35+
linkException: onPartial(failure, stackTrace),
3636
);
3737
}
3838
return false;
@@ -61,8 +61,10 @@ extension InternalQueryWriteHandling on QueryManager {
6161
response.data,
6262
queryResult,
6363
writeQuery: (req, data) => cache.writeQuery(req, data: data!),
64-
onPartial: (failure) => UnexpectedResponseStructureException(
64+
onPartial: (failure, stackTrace) =>
65+
UnexpectedResponseStructureException(
6566
failure,
67+
stackTrace,
6668
request: request,
6769
parsedResponse: response,
6870
),
@@ -84,8 +86,9 @@ extension InternalQueryWriteHandling on QueryManager {
8486
data,
8587
queryResult,
8688
writeQuery: writeQuery,
87-
onPartial: (failure) => MismatchedDataStructureException(
89+
onPartial: (failure, stackTrace) => MismatchedDataStructureException(
8890
failure,
91+
stackTrace,
8992
request: request,
9093
data: data,
9194
),

packages/graphql/lib/src/core/query_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ class QueryManager {
519519

520520
QueryResult<TParsed> _wrapFailure<TParsed>(
521521
BaseOptions<TParsed> options,
522-
dynamic ex,
522+
Object ex,
523523
StackTrace trace,
524524
) =>
525525
QueryResult(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import 'package:graphql/src/exceptions/network.dart'
1111
export 'package:graphql/src/exceptions/network.dart'
1212
if (dart.library.io) 'package:graphql/src/exceptions/network_io.dart';
1313

14-
LinkException translateFailure(dynamic failure, StackTrace trace) {
14+
LinkException translateFailure(Object failure, StackTrace trace) {
1515
if (failure is LinkException) {
1616
return failure;
1717
}
18-
return network.translateFailure(failure) ?? UnknownException(failure, trace);
18+
return network.translateFailure(failure, trace) ??
19+
UnknownException(failure, trace);
1920
}

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

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export 'package:normalize/normalize.dart' show PartialDataException;
1414
@immutable
1515
class CacheMissException extends LinkException {
1616
CacheMissException(this.message, this.request, {this.expectedData})
17-
: super(null);
17+
: super(null, null);
1818

1919
final String message;
2020
final Request request;
@@ -37,18 +37,25 @@ class CacheMissException extends LinkException {
3737
/// [CacheMisconfigurationException].
3838
class MismatchedDataStructureException extends LinkException {
3939
const MismatchedDataStructureException(
40-
this.originalException, {
40+
this.originalException,
41+
this.originalStackTrace, {
4142
this.request,
4243
required this.data,
43-
}) : super(originalException);
44+
}) : super(originalException, originalStackTrace);
4445

4546
final Map<String, dynamic>? data;
4647
final Request? request;
48+
49+
@override
4750
final PartialDataException originalException;
4851

52+
@override
53+
final StackTrace originalStackTrace;
54+
4955
@override
5056
String toString() => 'MismatchedDataStructureException('
5157
'$originalException, '
58+
'$originalStackTrace, '
5259
'request: ${request}, '
5360
'data: ${data}, '
5461
')';
@@ -62,11 +69,12 @@ class MismatchedDataStructureException extends LinkException {
6269
class CacheMisconfigurationException extends LinkException
6370
implements MismatchedDataStructureException {
6471
const CacheMisconfigurationException(
65-
this.originalException, {
72+
this.originalException,
73+
this.originalStackTrace, {
6674
this.request,
6775
this.fragmentRequest,
6876
required this.data,
69-
}) : super(originalException);
77+
}) : super(originalException, originalStackTrace);
7078

7179
final Request? request;
7280
final FragmentRequest? fragmentRequest;
@@ -75,10 +83,14 @@ class CacheMisconfigurationException extends LinkException
7583
@override
7684
final PartialDataException originalException;
7785

86+
@override
87+
final StackTrace originalStackTrace;
88+
7889
@override
7990
String toString() => [
8091
'CacheMisconfigurationException(',
8192
'$originalException, ',
93+
'$originalStackTrace, ',
8294
if (request != null) 'request: ${request}',
8395
if (fragmentRequest != null) 'fragmentRequest : ${fragmentRequest}',
8496
'data: ${data}, ',
@@ -94,12 +106,15 @@ class CacheMisconfigurationException extends LinkException
94106
class UnexpectedResponseStructureException extends ServerException
95107
implements MismatchedDataStructureException {
96108
const UnexpectedResponseStructureException(
97-
this.originalException, {
109+
this.originalException,
110+
this.originalStackTrace, {
98111
required this.request,
99112
required Response parsedResponse,
100113
}) : super(
101-
parsedResponse: parsedResponse,
102-
originalException: originalException);
114+
parsedResponse: parsedResponse,
115+
originalException: originalException,
116+
originalStackTrace: originalStackTrace,
117+
);
103118

104119
@override
105120
final Request request;
@@ -110,9 +125,13 @@ class UnexpectedResponseStructureException extends ServerException
110125
@override
111126
final PartialDataException originalException;
112127

128+
@override
129+
final StackTrace originalStackTrace;
130+
113131
@override
114132
String toString() => 'UnexpectedResponseStructureException('
115133
'$originalException, '
134+
'$originalStackTrace, '
116135
'request: ${request}, '
117136
'parsedResponse: ${parsedResponse}, '
118137
')';
@@ -124,13 +143,10 @@ class UnexpectedResponseStructureException extends ServerException
124143
class UnknownException extends LinkException {
125144
String get message => 'Unhandled Client-Side Exception: $originalException';
126145

127-
/// stacktrace of the [originalException].
128-
final StackTrace originalStackTrace;
129-
130146
const UnknownException(
131-
dynamic originalException,
132-
this.originalStackTrace,
133-
) : super(originalException);
147+
Object originalException,
148+
StackTrace originalStackTrace,
149+
) : super(originalException, originalStackTrace);
134150

135151
@override
136152
String toString() =>
@@ -147,8 +163,11 @@ class OperationException implements Exception {
147163
/// Errors encountered during execution such as network or cache errors
148164
LinkException? linkException;
149165

166+
StackTrace? originalStackTrace;
167+
150168
OperationException({
151169
this.linkException,
170+
this.originalStackTrace,
152171
Iterable<GraphQLError> graphqlErrors = const [],
153172
}) : this.graphqlErrors = graphqlErrors.toList();
154173

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import 'package:gql_link/gql_link.dart' show LinkException;
55
/// Exception occurring when there is a network-level error
66
class NetworkException extends LinkException {
77
NetworkException({
8-
dynamic originalException,
8+
required Object originalException,
9+
StackTrace originalStackTrace = StackTrace.empty,
910
this.message,
1011
required this.uri,
11-
}) : super(originalException);
12+
}) : super(originalException, originalStackTrace);
1213

1314
final String? message;
1415
final Uri? uri;
@@ -22,10 +23,11 @@ class NetworkException extends LinkException {
2223
/// Once `gql_link` has robust http and socket exception handling,
2324
/// this and `./network.dart` can be removed and `./exceptions_next.dart`
2425
/// will be all that is necessary
25-
NetworkException? translateFailure(dynamic failure) {
26+
NetworkException? translateFailure(Object failure, StackTrace stackTrace) {
2627
if (failure is http.ClientException) {
2728
return NetworkException(
2829
originalException: failure,
30+
originalStackTrace: stackTrace,
2931
message: failure.message,
3032
uri: failure.uri,
3133
);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ export './network.dart' show NetworkException;
88
/// Once `gql_link` has robust http and socket exception handling,
99
/// this and `./unhandled.dart` can be removed and `./exceptions_next.dart`
1010
/// will be all that is necessary
11-
base.NetworkException? translateFailure(dynamic failure) {
11+
base.NetworkException? translateFailure(Object failure, StackTrace stackTrace) {
1212
if (failure is io.SocketException) {
1313
return base.NetworkException(
1414
originalException: failure,
15+
originalStackTrace: stackTrace,
1516
message: failure.message,
1617
uri: Uri(
1718
scheme: 'http',
@@ -20,5 +21,5 @@ base.NetworkException? translateFailure(dynamic failure) {
2021
),
2122
);
2223
}
23-
return base.translateFailure(failure);
24+
return base.translateFailure(failure, stackTrace);
2425
}

packages/graphql/pubspec.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ homepage: https://github.com/zino-app/graphql-flutter/tree/master/packages/graph
66
dependencies:
77
meta: ^1.3.0
88
path: ^1.8.0
9-
gql: ^0.13.0
10-
gql_exec: ^0.4.0
11-
gql_link: ^0.4.2
12-
gql_http_link: ^0.4.2
13-
gql_transform_link: ^0.2.0
14-
gql_error_link: ^0.2.0
15-
gql_dedupe_link: ^2.0.0
9+
gql: ^0.14.0
10+
gql_exec: ^0.4.1
11+
gql_link: ^0.5.0
12+
gql_http_link: ^0.4.4+1
13+
gql_transform_link: ^0.2.2
14+
gql_error_link: ^0.2.3
15+
gql_dedupe_link: ^2.0.3
1616
hive: ^2.1.0
17-
normalize: ^0.6.0
17+
normalize: ^0.7.1
1818
http: ^0.13.0
1919
collection: ^1.15.0
2020
web_socket_channel: ^2.0.0

0 commit comments

Comments
 (0)