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
  • Loading branch information
ykuc7 committed Jul 19, 2024
1 parent 0b1b327 commit 195326f
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 @@ -27,6 +27,7 @@ class QueryManager {
required this.link,
required this.cache,
this.alwaysRebroadcast = false,
this.requestTimeout = const Duration(seconds: 5),
}) {
scheduler = QueryScheduler(
queryManager: this,
Expand All @@ -39,6 +40,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 @@ -244,8 +248,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 @@ -26,11 +26,13 @@ class GraphQLClient implements GraphQLDataProxy {
required this.cache,
DefaultPolicies? defaultPolicies,
bool alwaysRebroadcast = false,
Duration queryRequestTimeout = const Duration(seconds: 5),
}) : defaultPolicies = defaultPolicies ?? DefaultPolicies(),
queryManager = QueryManager(
link: link,
cache: cache,
alwaysRebroadcast: alwaysRebroadcast,
requestTimeout: queryRequestTimeout,
);

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

0 comments on commit 195326f

Please sign in to comment.