graphql-flutter icon indicating copy to clipboard operation
graphql-flutter copied to clipboard

Query never ends if network gets disconnected

Open toritroniks opened this issue 5 years ago • 16 comments

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.

toritroniks avatar Jan 17 '20 05:01 toritroniks

I got the same error

agungnursatria avatar Jan 20 '20 04:01 agungnursatria

I think you can use an ErrorLink where your Link is.

jifalops avatar Feb 09 '20 06:02 jifalops

Confirming the issue.

SanjiKir avatar Mar 30 '20 22:03 SanjiKir

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,
    );
  }
}

ant-ds avatar May 18 '20 11:05 ant-ds

+1

gouravd avatar May 26 '20 13:05 gouravd

Same problem

MoyaMaker avatar May 26 '20 15:05 MoyaMaker

https://github.com/zino-app/graphql-flutter/issues/327

comerc avatar Jul 01 '20 12:07 comerc

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

vytautas-pranskunas- avatar Jul 17 '20 11:07 vytautas-pranskunas-

any progress?

a-reznic avatar Nov 10 '20 18:11 a-reznic

any progress?

vytautas-pranskunas- avatar Feb 02 '21 12:02 vytautas-pranskunas-

+1

Bligoubloups avatar Apr 14 '22 13:04 Bligoubloups

Try gql_dio_link

dehypnosis avatar Jun 14 '22 08:06 dehypnosis

+1

abarrettPS avatar Sep 01 '22 21:09 abarrettPS

+1

PhantomRay avatar Sep 20 '22 09:09 PhantomRay