Skip to content

Commit

Permalink
fix(graphql): add query timeout argument when create client.
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/graphql/lib/src/core/query_manager.dart
#	packages/graphql/lib/src/graphql_client.dart
  • Loading branch information
ykuc7 committed Aug 29, 2024
1 parent 59bb1d5 commit 6180841
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/graphql/lib/src/core/query_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class QueryManager {
this.alwaysRebroadcast = false,
DeepEqualsFn? deepEquals,
bool deduplicatePollers = false,
this.requestTimeout = const Duration(seconds: 5),
}) {
scheduler = QueryScheduler(
queryManager: this,
Expand All @@ -51,6 +52,9 @@ class QueryManager {
/// Whether to skip deep equality checks in [maybeRebroadcastQueries]
final bool alwaysRebroadcast;

/// The timeout for resolving a query
final Duration requestTimeout;

QueryScheduler? scheduler;
static final _oneOffOpId = '0';
int idCounter = 1;
Expand Down Expand Up @@ -256,8 +260,7 @@ class QueryManager {

try {
// execute the request through the provided link(s)
response =
await link.request(request).timeout(Duration(seconds: 5)).first;
response = await link.request(request).timeout(this.requestTimeout).first;

queryResult = mapFetchResultToQueryResult(
response,
Expand Down
2 changes: 2 additions & 0 deletions packages/graphql/lib/src/graphql_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class GraphQLClient implements GraphQLDataProxy {
bool alwaysRebroadcast = false,
DeepEqualsFn? deepEquals,
bool deduplicatePollers = false,
Duration queryRequestTimeout = const Duration(seconds: 5),
}) : defaultPolicies = defaultPolicies ?? DefaultPolicies(),
queryManager = QueryManager(
link: link,
cache: cache,
alwaysRebroadcast: alwaysRebroadcast,
deepEquals: deepEquals,
deduplicatePollers: deduplicatePollers,
requestTimeout: queryRequestTimeout,
);

/// The default [Policies] to set for each client action
Expand Down

0 comments on commit 6180841

Please sign in to comment.