Created
July 16, 2024 19:44
-
-
Save Neelansh-ns/7cfa1e3fec10682547161e234675a3ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:graphql/client.dart'; | |
class HttpTimeoutLink extends HttpLink { | |
final Duration queryTimeout; | |
final Duration mutationTimeout; | |
HttpTimeoutLink({ | |
required String uri, | |
required this.mutationTimeout, | |
required this.queryTimeout, | |
}) : super(uri); | |
@override | |
Stream<Response> request(Request request, [NextLink? forward]) async* { | |
final stream = super.request(request, forward).first.timeout( | |
request.isQuery ? queryTimeout : mutationTimeout, | |
onTimeout: () => throw "Request timed out", | |
); | |
yield* stream.asStream(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment