From 4f0c4286bd03cfb65e47eaec01c1a3a262e33d0e Mon Sep 17 00:00:00 2001 From: Hamed Rezaee <57184669+hamed-rezaee@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:07:52 +0100 Subject: [PATCH] feat(graphql_common): add queryRequestTimeout parameter to GraphQLClient class --- packages/graphql/lib/src/graphql_client.dart | 26 ++++++---- .../graphql/test/graphql_client_test.dart | 48 +++++++++++++++++++ 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/packages/graphql/lib/src/graphql_client.dart b/packages/graphql/lib/src/graphql_client.dart index 6d7a1edfd..25c2e1a73 100644 --- a/packages/graphql/lib/src/graphql_client.dart +++ b/packages/graphql/lib/src/graphql_client.dart @@ -51,16 +51,24 @@ class GraphQLClient implements GraphQLDataProxy { late final QueryManager queryManager; /// Create a copy of the client with the provided information. - GraphQLClient copyWith( - {Link? link, - GraphQLCache? cache, - DefaultPolicies? defaultPolicies, - bool? alwaysRebroadcast}) { + GraphQLClient copyWith({ + Link? link, + GraphQLCache? cache, + DefaultPolicies? defaultPolicies, + bool? alwaysRebroadcast, + DeepEqualsFn? deepEquals, + bool deduplicatePollers = false, + Duration? queryRequestTimeout, + }) { return GraphQLClient( - link: link ?? this.link, - cache: cache ?? this.cache, - defaultPolicies: defaultPolicies ?? this.defaultPolicies, - alwaysRebroadcast: alwaysRebroadcast ?? queryManager.alwaysRebroadcast); + link: link ?? this.link, + cache: cache ?? this.cache, + defaultPolicies: defaultPolicies ?? this.defaultPolicies, + alwaysRebroadcast: alwaysRebroadcast ?? queryManager.alwaysRebroadcast, + deepEquals: deepEquals, + deduplicatePollers: deduplicatePollers, + queryRequestTimeout: queryRequestTimeout ?? queryManager.requestTimeout, + ); } /// This registers a query in the [QueryManager] and returns an [ObservableQuery] diff --git a/packages/graphql/test/graphql_client_test.dart b/packages/graphql/test/graphql_client_test.dart index f9401f9eb..74572c966 100644 --- a/packages/graphql/test/graphql_client_test.dart +++ b/packages/graphql/test/graphql_client_test.dart @@ -1447,5 +1447,53 @@ query WalletGetContent($input: WalletGetContentInput!) { equals('bar'), ); }); + + group('GraphQLClient copyWith', () { + late GraphQLClient client; + late Link link; + late GraphQLCache cache; + + setUp(() { + link = MockLink(); + cache = GraphQLCache(); + client = GraphQLClient(link: link, cache: cache); + }); + + test('copyWith updates link', () { + final newLink = MockLink(); + final newClient = client.copyWith(link: newLink); + + expect(newClient.link, equals(newLink)); + expect(newClient.cache, equals(client.cache)); + }); + + test('copyWith updates cache', () { + final newCache = GraphQLCache(); + final newClient = client.copyWith(cache: newCache); + + expect(newClient.cache, equals(newCache)); + expect(newClient.link, equals(client.link)); + }); + + test('copyWith updates defaultPolicies', () { + final newDefaultPolicies = DefaultPolicies(); + final newClient = client.copyWith(defaultPolicies: newDefaultPolicies); + + expect(newClient.defaultPolicies, equals(newDefaultPolicies)); + }); + + test('copyWith updates alwaysRebroadcast', () { + final newClient = client.copyWith(alwaysRebroadcast: true); + + expect(newClient.queryManager.alwaysRebroadcast, isTrue); + }); + + test('copyWith updates queryRequestTimeout', () { + final newTimeout = Duration(seconds: 10); + final newClient = client.copyWith(queryRequestTimeout: newTimeout); + + expect(newClient.queryManager.requestTimeout, equals(newTimeout)); + }); + }); }); }