Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphql): add query timeout argument when create client. #1447

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading