Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached data is not available on the QueryResult when there is a network error. #718

Closed
jifalops opened this issue Sep 1, 2020 · 5 comments

Comments

@jifalops
Copy link

jifalops commented Sep 1, 2020

Describe the bug
Cached data is not available on the QueryResult when there is a network error.

To Reproduce
Steps to reproduce the behavior:

  1. Set-up
GraphQLProvider(
      client: ValueNotifier<GraphQLClient>(
        GraphQLClient(
          cache: OptimisticCache(dataIdFromObject: _idFromObject),
          link: myLink,
        ),
      ),
      child: CacheProvider(
        child: MaterialApp(
  ...
  1. Run a query and get the results.
class MyQuery extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Query(
      options: QueryOptions(
        // query is of a type generated by the `artemis` package
        documentNode: query.document,
      ),
      builder: (
        QueryResult result, {
        Future<QueryResult> Function() refetch,
        FetchMore fetchMore,
      }) {
        if (result.hasException) {
          return Text('${result.exception}');
        } else if (result.loading) {
          return Center(child: CircularProgressIndicator());
        }

        final items = query.parse(result.data);

        return Column(
          children: [
            ...items.map((item) => ListTile(
                  title: Text(item.name),
                  subtitle: Text('${item.typeName} ${item.id}'),
                ))
          ],
        );
      },
    );
  }
}
  1. Enable airplane mode on the device
  2. Press home and open another app (so the cache write is triggered)
  3. Restart the app (hot restart). The result is now the network error and no cached data is available.

Expected behavior
Enabling airplane mode and hot-restarting the app should allow it to return the cached results.

Desktop (please complete the following information):

  • OS: Ubuntu 20.04

Smartphone (please complete the following information):

  • Device: Android emulator API 29

Additional context
Flutter beta 1.21.0-9.2.pre

@jifalops jifalops changed the title Cached results not used when offline Cached data is not available on the QueryResult when there is a network error. Sep 1, 2020
@micimize
Copy link
Collaborator

Can you try this with 4.0.0-alpha.5?

@micimize micimize added the ⌛ reproduction needed Issue is subtle and requires a true accessible reproduction to debug label Oct 7, 2020
@micimize
Copy link
Collaborator

micimize commented Oct 7, 2020

This is outdated / likely solved by the cache rework 4.0.0-beta.1 (#648). Also this may just be because of the hot restart.

Please make a reproduction that doesn't involve live reload for testing

@micimize micimize removed the ⌛ reproduction needed Issue is subtle and requires a true accessible reproduction to debug label Oct 25, 2020
@micimize
Copy link
Collaborator

looked at this again and added a mechanism for carrying forward errors in #754

@jifalops
Copy link
Author

i actually solved it with an HTTP link that caches queries. I think that is what's right for my use case.

@micimize
Copy link
Collaborator

micimize commented Nov 6, 2020

Closed by #754

@micimize micimize closed this as completed Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants