-
Notifications
You must be signed in to change notification settings - Fork 786
Include cached data with error #548
Include cached data with error #548
Conversation
Can you add a test for this as well? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @StevePotter. I think this is a behavior we should change in Apollo Client, but sort of that, this might be a good PR to patch things up. A test is definitely needed though.
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "react-apollo", | |||
"version": "1.0.0-rc.3", | |||
"version": "1.0.0-rc.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll update the package.json ourselves, this should not be in here.
Changelog.md
Outdated
@@ -4,6 +4,9 @@ Expect active development and potentially significant breaking changes in the `0 | |||
|
|||
### vNext | |||
|
|||
### 1.0.0-rc.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just put this under vNext, and we'll figure out which version we'll release it under.
src/graphql.tsx
Outdated
if (error) { | ||
let previousResult = this.queryObservable.getLastResult(); | ||
if (previousResult && !previousResult.error) { | ||
dataToMerge = assign({}, previousResult.data, currentResult.data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's pretty hard to predict what data you'd get here if there ever is any data in currentResult
. I think it might be better to just return the previous result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @helfer thanks for the review. I'm happy you're encouraged by this PR. Please give me a few days to update the PR as I'm swamped on a few higher priority issues. I'll get the appropriate testes in there and clean up the currentResult stuff and just use getLastResult().
Thanks again!
@helfer I tightened up the code and added test coverage. This one is good to go. The test:
The test fails without my change to |
@helfer how about now? It's clean, tested, and green. |
Another PR I submitted to apollo-client that doesn't affect this one but it needed for a solid offline UX apollographql/apollo-client#1601 |
Thanks @StevePotter, the test looks good! This could technically break apps if a component only checks for data but not |
This PR includes data cached from the Apollo store when there is an error while fetching the query. Now useful data can be displayed along with any error message.
For example, the server is down. An error will be returned as it always was. But until now, the
data
prop was empty. A good UI for this situation would be to display an error message like "There was an error reaching our servers. Until the problem is fixed, you can still use the app. Your data might just be a bit off." and show the cached data. Now you can!