From 6180841e9b703d9c312ea29e575dece973c691bc Mon Sep 17 00:00:00 2001 From: ykuc7 Date: Fri, 19 Jul 2024 14:09:28 +0900 Subject: [PATCH] fix(graphql): add query timeout argument when create client. # Conflicts: # packages/graphql/lib/src/core/query_manager.dart # packages/graphql/lib/src/graphql_client.dart --- packages/graphql/lib/src/core/query_manager.dart | 7 +++++-- packages/graphql/lib/src/graphql_client.dart | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/graphql/lib/src/core/query_manager.dart b/packages/graphql/lib/src/core/query_manager.dart index 1a7351fb..375707f0 100644 --- a/packages/graphql/lib/src/core/query_manager.dart +++ b/packages/graphql/lib/src/core/query_manager.dart @@ -35,6 +35,7 @@ class QueryManager { this.alwaysRebroadcast = false, DeepEqualsFn? deepEquals, bool deduplicatePollers = false, + this.requestTimeout = const Duration(seconds: 5), }) { scheduler = QueryScheduler( queryManager: this, @@ -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; @@ -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, diff --git a/packages/graphql/lib/src/graphql_client.dart b/packages/graphql/lib/src/graphql_client.dart index 357419b8..6d7a1edf 100644 --- a/packages/graphql/lib/src/graphql_client.dart +++ b/packages/graphql/lib/src/graphql_client.dart @@ -28,6 +28,7 @@ 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, @@ -35,6 +36,7 @@ class GraphQLClient implements GraphQLDataProxy { alwaysRebroadcast: alwaysRebroadcast, deepEquals: deepEquals, deduplicatePollers: deduplicatePollers, + requestTimeout: queryRequestTimeout, ); /// The default [Policies] to set for each client action