graphql-flutter
graphql-flutter copied to clipboard
Query never ends if network gets disconnected
If I disconnect the internet during a graphql query, the code never throws an exception and never continues to the next line.
Steps to reproduce
- Run a query that takes a little long to finish.
- While the query is running, turn of the internet.
- Notice that the code does not throw an exception and never finishes.
Expected behavior I believe an exception should be thrown.
Sample code:
try {
GraphQLClient client = GraphQLClient(
cache: InMemoryCache(),
link: link,
);
print('start query');
final result = await client.query( // disconnect the internet during this function
QueryOptions(
documentNode: gql(myQuery),
variables: myVariables,
),
);
print('end query'); // this is never printed
} catch (e) {
print('error'); // this is never printed
}
I thought on using CancelableOperation to make some kind of timeout, but the actual function would still be running on the background.
Am I doing something wrong? Any help would be appreciated.
Smartphone:
- Device: iPhoneX
- Version 13.3
Package:
- graphql_flutter: 3.0.0
Additional Info:
λ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.17134.1246], locale ja-JP)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 3.5)
[!] IntelliJ IDEA Ultimate Edition (version 2018.3)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[√] VS Code (version 1.41.1)
[√] Connected device (1 available)
! Doctor found issues in 1 category.
I got the same error
I think you can use an ErrorLink where your Link is.
Confirming the issue.
I think you can use an
ErrorLinkwhere yourLinkis.
Could you elaborate? I got the exact same code, my link is an HttpLink (with uri=serveradress). What would I need to change to e.g: the following code:
class GraphQLConfiguration {
static HttpLink httpLink = HttpLink(
uri: "https://link.to.server.com",
);
ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
link: httpLink,
cache: OptimisticCache(dataIdFromObject: typenameDataIdFromObject),
),
);
GraphQLClient clientToQuery() {
return GraphQLClient(
cache: OptimisticCache(dataIdFromObject: typenameDataIdFromObject),
link: httpLink,
);
}
}
+1
Same problem
https://github.com/zino-app/graphql-flutter/issues/327
Any progress here? This is very annoying issue. It would very nasty to go to each query and set timeouts....
any progress?
any progress?
+1
Try gql_dio_link
+1
+1