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

Cache update with optimisticResponse #19

Closed
awaik opened this issue Apr 12, 2020 · 2 comments · Fixed by #47
Closed

Cache update with optimisticResponse #19

awaik opened this issue Apr 12, 2020 · 2 comments · Fixed by #47

Comments

@awaik
Copy link
Contributor

awaik commented Apr 12, 2020

Description

During diving into the code for #18, I found some problems with the cache update with optimisticResponse.

If we make the mutation with Optimistic Response

final mutation = ProfileBmiMutation2(
  buildVars: (b) => b..input = profileInput,
  updateCacheHandlerKey: IdCacheHandlers.profileBmiMutation,
  optimisticResponse: optimisticRequest,
).copyWith(
  context: Context.fromList(
    [
      HttpLinkHeaders(
        headers: idToken,
      ),
    ],
  ),
);
client
    .responseStream(mutation)
    .firstWhere((response) => response.optimistic)
    .then((response) {});

cache updates incorrectly.

Assumption where the bug is

Maybe it is connected with code here /lib/src/cache/cache_proxy.dart, because if we change optimistic: _optimistic, to optimistic: false, it starts to work correctly (in this exact use-case).
I guess, there is more logic. I just pointed out what I've found.

  void writeQuery(
    Request request,
    Map<String, dynamic> data,
  ) =>
      _cache.writeQuery(
        request,
        data,
        optimistic: false,
        queryId: _queryId,
      );

Screenshot

  1. When we make the first request cache is not updated.
  2. But if we open the screen again, cache updates.
  3. After that, other updates do not change the cache.

ezgif com-video-to-gif (2)

@smkhalsa
Copy link
Member

@awaik can you add a failing test for this, and I'll take a look?

@awaik
Copy link
Contributor Author

awaik commented Apr 28, 2020

@smkhalsa ok, I do it after finishing the example with mutations

This issue was closed.
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

Successfully merging a pull request may close this issue.

2 participants