Skip to content

Commit

Permalink
Merge pull request #1447 from ykuc7/fix-add-timeout-argument-to-creat…
Browse files Browse the repository at this point in the history
…e-client

fix(graphql): add query timeout argument when create client.
  • Loading branch information
vincenzopalazzo authored Aug 29, 2024
2 parents 59bb1d5 + 6180841 commit ff0ea7c
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 ff0ea7c

Please sign in to comment.