Graphql-flutter: Query never ends if network gets disconnected

Created on 17 Jan 2020  路  10Comments  路  Source: zino-app/graphql-flutter

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

  1. Run a query that takes a little long to finish.
  2. While the query is running, turn of the internet.
  3. 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.
link

Most helpful comment

Any progress here? This is very annoying issue.
It would very nasty to go to each query and set timeouts....

All 10 comments

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 ErrorLink where your Link is.

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

Any progress here? This is very annoying issue.
It would very nasty to go to each query and set timeouts....

any progress?

any progress?

Was this page helpful?
0 / 5 - 0 ratings