-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Network-only refetch after network error does not update networkStatus #1622
Comments
@msmfsd I remember recently fixing a related issue. Can you check that this is still the case with the latest version? If it is, could you create a reproduction with the error template? It should be possible to simulate a network error by simply throwing an error in the network interface the first time it's called: https://github.com/apollographql/react-apollo-error-template/blob/master/src/graphql/networkInterface.js |
@helfer I updated libs and no change. I did create an error template and could not replicate the error at all. We have a large, complex app connected to a ruby backend with relay graphql and the issue happens on some components and not on others - and the components are quite similar.. We are using a refetching state as a workaround and it works fine so perhaps I will revisit this at a later point in time. Thanks for all help and I will update these issues if I can in future. |
For anyone looking for the refetch workaround:
|
Thanks @msmfsd! If anyone could make a reproduction, that would be greatly appreciated. I think it's related to a similar issue on react-apollo about loading state not updating. |
This issue has been automatically closed because it has not had recent activity after being marked as stale. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to Apollo Client! |
@jbaxleyiii : here are some precisions. I work on a React Native project with: I have a component "connected" using graphql HOC. I have a setInterval to trigger a refetch of the query. If a refetch fails, then the data.error remains, even if a refetch has succeeded after the fail. Is it enough information for your to have a look at this issue ? |
@Jay1337 I'm having the same problem although I'm using Apollo client 1.x I have a HOC query with a polling interval. If some network error occurs once, every future request will carry the past error despite returning good data. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to Apollo Client! |
Hey! This is still an important and open issue! |
@Jay1337 agreed! apollo please fix loading state updating issues. |
+1 |
@jbaxleyiii Looks like i fill issue with same problem in react-apollo issue. I put investigation result and reproduction steps in last sections of bugreport |
I'm going to add this to the post 2.0 bug milestone to make sure it is prioritized and fixed for everyone! Sorry for the delay! |
this Error is happing in 2.0.4 , it's very simple to test in network-only, turn off the server , and navigate page and when those pages give error, turn on the server, and try again, the props.query.error value keeps ... with the error, despite apollo is calling the page and on the network tab , data is sent from the server to the client, the problem that data is not loading... how I can help, in where code i can look for ? |
@webmobiles I think a failing test for this scenario would be helpful |
@n1ru4l how I could to do a failing test ? I can send you in private an acess to the app? |
For anyone having this issue, I seem to be having better luck after upgrading to the latest release of apollo-link-retry, which seems to have just been released. At the time of this comment, that version was 2.0.0 (I had been using version 1.0.x). When I shut down my dev server and run a query, the query fails. Then I restart my server and do a refetch and it works as anticipated. -- edit -- |
Thanks @adambom - wish there was some update on these and similar issues, seems like v2 has been live for ages with these issues.. |
@adambom can you possibly provide some code example of your use of apollo-link-retry? |
I think they version all their libraries differently: apollo-client has been at 2.0 for a while but the link packages are mostly still at 1.x. Here's the release I'm talking about: https://github.com/apollographql/apollo-link/releases/tag/apollo-link-retry%402.0.0 I'm not doing anything too different from the documentation example. If you just follow the example here you should get the behavior I'm describing. That said, I've customized the behavior a little bit. I don't want network errors to crash the app, so I've prevented it from doing so by forcing apollo to retry on network errors forever. Graphql errors will still be handled the normal way, but here's what I've done: export const errorBus = new EventEmitter();
const withRetries = new RetryLink({
delay: {
max: 30 * 1000,
},
attempts: (count, operation, error) => {
console.log(`Retrying operation ${operation.operationName} (Attempt ${count})`);
if (!!error) {
errorBus.emit('error', error);
}
return !!error;
}
});
const httpLink = new HttpLink({ uri: [Config.GRAPHQL_URI, 'graphql'].join('/') });
const errorHandler = onError(options => {
errorBus.emit('error', options);
});
let link = ApolloLink.from([
errorHandler,
withRetries,
httpLink,
]);
export const client = new ApolloClient({
link,
cache: new InMemoryCache(),
}); So the idea here is that if there's ever a network error (RetryLink ignores GraphqlErrors for some reason - by design) we just keep retrying. You could could program it to give up at some point, if you wanted, but in the event of a network error, I'm assuming it's because of bad connectivity and I want to reconnect at some point in the future. To notify any components that an error has occured, I create an EventEmitter and emit events. Anyone who cares there's been an error can subscribe to that emitter. |
thanks @adambom much appreciated 👍 |
@helfer currently network errors crash the app in that they can't be caught, and they remove the query from the store making it impossible to refresh. Transient network errors are sure to happen from time to time. |
I'm seeing similar issues with Sounds like my expected results are valid...
It also sounds like some of you are seeing your However, I'm not having any luck refreshing the UPDATE: While super interesting and also useful, |
I have the same problem with : Problem
DemoHere is a demo based on the react-apollo-error-template and starts a minimal node server to simulate the network errors: This problem is a duplicate of installing |
@adambom Your workaround with RetryLink is the only option that is a possible to workaround #2258. I also thought about using a link that reads the data from the cache in case of a network error (and publishes that to the the observable). However since I could not figure out how to read connections from the cache this was not possible for me. |
Easy to reproduce, hard to fix. Block me too long. 😭 |
@aheissenberger It's gone after install |
react-apollo@^2.1.0 fixes it 🙌 |
It looks like it is fixed in 2.1.0, but is broken again in 2.1.1 |
I can confirm that it works on |
Confirmed that its broken in |
Seems to be still broken in |
Same in 2.1.6..... |
I've updated the most recent reproduction (provided in #1622 (comment)) to use |
Unfortunately, in my case even after update to EDIT: Everything works as expected :) |
Versions
NOTE: this needs a seperate backend grpahql server to re-create so I have not created a
react-apollo-error-template
repo.Intended outcome:
Refetching a query after network error should always update loading to true and networkStatus to 4 - until either success or error happens.
Actual outcome:
NetworkStatus remains at 8 and loading remains set to false on refetch. Only once server is up again and refetch completes susseccfully does networkStatus update to 7, and loading remains false the entire time.
How to reproduce the issue:
fetchPolicy: 'network-only', notifyOnNetworkStatusChange: true
.<a onClick={() => refetch()>Try again</a>
if error is true.Related issues
See apollographql/react-apollo#642
The text was updated successfully, but these errors were encountered: