Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

notifyOnNetworkStatusChange does not work after an error occurs #2926

Closed
Collin3 opened this issue Apr 3, 2019 · 1 comment · Fixed by apollographql/apollo-client#4992
Closed
Assignees
Labels
bug-upstream Bug confirmed to originate from a dependency has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository

Comments

@Collin3
Copy link

Collin3 commented Apr 3, 2019

Intended outcome:

const withGraphQlQuery = graphql(someQuery, {
    options: () => ({
        notifyOnNetworkStatusChange: true,
    }),
    props: ({data}) => {
        console.log('data', data);
        
        return data;
    }
});

In the above example I have some code in my actual presentational component that does error handling and displays a button that will call data.refetch() when pressed. When a network error occurs and then you tap said button, I would expect refetch to be called and for data to be logged with a networkStatus of 4 (when it's refetching), and then a second time once the response comes back with a networkStatus of 7 (when it gets a response and is ready).

Actual outcome:

When I actually tried this out, I did not receive the first console log statement I expected. Instead I only got notified of the networkStatus of 7 response.

Screen Shot 2019-04-03 at 4 45 45 PM

One interesting thing to note is that when the network request is successful and I try to refetch, it will log out the responses I was expecting in the error scenario.
Screen Shot 2019-04-03 at 4 51 45 PM

Another interesting note is that I'm able to get the expected console log statements with the networkStatus of 4 while refetching if there is a network error, I have notifyOnNetworkStatusChange set to true AND I have an errorPolicy of all. However, setting this errorPolicy has other side effects and I don't think it should be necessary to set an errorPolicy and notifyOnNetworkStatusChange option just to get notified of network status changes....

How to reproduce the issue:

If I get time I will add the reproduction using the error template, but you should be able to reproduce by using any HOC query with a similar format as mine listed above, and then forcing a network error and trying to refetching. When you attempt a refetch after an error response then you never get notified of the networkStatus changing to 4.

Version

  • apollo-client@2.4.0
  • react-apollo@2.5.3
@jasonpaulos jasonpaulos self-assigned this Jun 20, 2019
@jasonpaulos jasonpaulos added the has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository label Jun 20, 2019
@jasonpaulos
Copy link
Contributor

jasonpaulos commented Jun 20, 2019

I created this reproduction that proves the issue still exists: https://codesandbox.io/s/react-apollo-issue-2926-o1ryu

This is an issue with apollo-client, and I am working on creating a fix to be included in its next version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug-upstream Bug confirmed to originate from a dependency has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants