From 701cd3399fd55c6d4edba54abd24a3c3f4d84f32 Mon Sep 17 00:00:00 2001 From: Yusuke Mori Date: Sun, 12 Nov 2023 00:55:48 +0900 Subject: [PATCH] fix(ferry): Fix problem with operationRequest generated on initial request being included in response each time. (#545) * fix(ferry)!: Fix problem with operationRequest generated on initial request being included in response each time. This is a breaking change because the received request now has a different object identity and the send request, which some users might have relied on. --- packages/ferry/lib/ferry_isolate.dart | 4 +- .../test/isolate/isolate_client_test.dart | 57 ++++++++++++------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/packages/ferry/lib/ferry_isolate.dart b/packages/ferry/lib/ferry_isolate.dart index 6b9d1e36..e1041967 100644 --- a/packages/ferry/lib/ferry_isolate.dart +++ b/packages/ferry/lib/ferry_isolate.dart @@ -99,8 +99,8 @@ class IsolateClient extends TypedLink { return _handleStreamCommand>( (port) => RequestCommand(port.sendPort, request), (response, sink) => sink.add(OperationResponse( - operationRequest: request, - linkException: response!.linkException, + operationRequest: response!.operationRequest, + linkException: response.linkException, graphqlErrors: response.graphqlErrors, dataSource: response.dataSource, extensions: response.extensions, diff --git a/packages/ferry/test/isolate/isolate_client_test.dart b/packages/ferry/test/isolate/isolate_client_test.dart index 0c81ea5f..e5f9d060 100644 --- a/packages/ferry/test/isolate/isolate_client_test.dart +++ b/packages/ferry/test/isolate/isolate_client_test.dart @@ -150,18 +150,26 @@ void main() { unawaited(expectLater( stream, emitsInOrder([ - OperationResponse( - data: GHumanWithArgsData((b) => b - ..human.id = '1' - ..human.name = 'Luke'), - dataSource: DataSource.Link, - operationRequest: req), - OperationResponse( - data: GHumanWithArgsData((b) => b - ..human.id = '2' - ..human.name = 'Bert'), - dataSource: DataSource.Cache, - operationRequest: req), + isA>() + .having( + (p) => p.data, + 'data', + GHumanWithArgsData((b) => b + ..human.id = '1' + ..human.name = 'Luke')) + .having((p) => p.linkException, 'linkException', isNull) + .having((p) => p.graphqlErrors, 'errors', isNull) + .having((p) => p.dataSource, 'source', DataSource.Link), + isA>() + .having( + (p) => p.data, + 'data', + GHumanWithArgsData((b) => b + ..human.id = '2' + ..human.name = 'Bert')) + .having((p) => p.linkException, 'linkException', isNull) + .having((p) => p.graphqlErrors, 'errors', isNull) + .having((p) => p.dataSource, 'source', DataSource.Cache), emitsDone, ]))); @@ -189,16 +197,21 @@ void main() { unawaited(expectLater( stream, emitsInOrder([ - OperationResponse( - data: GHumanWithArgsData((b) => b - ..human.id = '1' - ..human.name = 'Luke'), - dataSource: DataSource.Link, - operationRequest: req), - OperationResponse( - operationRequest: req, - data: null, - dataSource: DataSource.Cache), + isA>() + .having( + (p) => p.data, + 'data', + GHumanWithArgsData((b) => b + ..human.id = '1' + ..human.name = 'Luke')) + .having((p) => p.linkException, 'linkException', isNull) + .having((p) => p.graphqlErrors, 'errors', isNull) + .having((p) => p.dataSource, 'source', DataSource.Link), + isA>() + .having((p) => p.data, 'data', isNull) + .having((p) => p.linkException, 'linkException', isNull) + .having((p) => p.graphqlErrors, 'errors', isNull) + .having((p) => p.dataSource, 'source', DataSource.Cache), emitsDone, ])));