Skip to content

Commit

Permalink
feat(graphql_common): add queryRequestTimeout parameter to GraphQLCli…
Browse files Browse the repository at this point in the history
…ent class
  • Loading branch information
hamed-rezaee committed Oct 31, 2024
1 parent 9e21fd5 commit 4f0c428
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/graphql/lib/src/graphql_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
48 changes: 48 additions & 0 deletions packages/graphql/test/graphql_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
});
}

0 comments on commit 4f0c428

Please sign in to comment.