Skip to content

Fixes repeatedly throwing incorrect errors when queries hits cache immediately after an Apollo error #343

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

Merged
merged 1 commit into from
Nov 8, 2018
Merged

Conversation

miel-dev0
Copy link
Contributor

Since v3.0.0-beta.14, query subscription is restarted after an error. This works well in most cases, but if an error occurs and subsequent queries hit the cache, the same error is thrown repeatedly instead of the correct value being fetched from the cache.

To demonstrate the behavior, let's say we have a resolver which accepts two arguments - value, and do_throw. if do_throw is false the resolver simply echoes value and if do_throw is true it throws an error with value.

Pseudocode:

executeApollo({"value":"1","do_throw":false}) // 1
executeApollo({"value":"12","do_throw":false}) // 12
executeApollo({"value":"123","do_throw":true}) // GraphQL error: Error: 123
executeApollo({"value":"1","do_throw":false}) // GraphQL error: Error: 123 (incorrect)
executeApollo({"value":"12","do_throw":false}) // GraphQL error: Error: 123 (incorrect)
executeApollo({"value":"4","do_throw":false}) // 4
executeApollo({"value":"1","do_throw":false}) // 1 (cached).  Queries run as expected after a cache miss

The problem is likely to be an upstream issue in Apollo, nevertheless, it can be resolved easily by not reusing SmartQuery.observer and creating an observer each time executeApollo() is called. (Or at least after an error has occurred.)

@miel-dev0 miel-dev0 changed the title Fixes incorrect errors when a query hits cache immediately after an Apollo error Fixes repeated throwing incorrect errors when queries hits cache immediately after an Apollo error Jul 27, 2018
@miel-dev0 miel-dev0 changed the title Fixes repeated throwing incorrect errors when queries hits cache immediately after an Apollo error Fixes repeatedly throwing incorrect errors when queries hits cache immediately after an Apollo error Jul 27, 2018
@Akryum
Copy link
Member

Akryum commented Aug 30, 2018

@hwillson What do you think?

@SebastienTainon
Copy link

This PR would also solve #425 which is a similar case. The problem is that the current code doesn't handle well the Apollo Client cache hits, they are not observed the way they should and thus Vue-apollo doesn't get the results like he does when the cache is missed.

@sadnub
Copy link

sadnub commented Oct 28, 2018

This might also fix my issue. #435

@Akryum Akryum merged commit 202103a into vuejs:master Nov 8, 2018
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 this pull request may close these issues.

4 participants