Apollo-client: refetchQueries doesn't indicate that query is loading

Created on 3 Feb 2017  ·  6Comments  ·  Source: apollographql/apollo-client

Intended outcome:
A mutation has refetchQueries option that refetches someQuery. someQuery should now have loading true so that the app can indicate to the user that the data is loading.

Actual outcome:
someQuery has loading as false with the stale data. It then updates with loading false with the new data, never indicating that data is loading.

Most helpful comment

@helfer just opened #1263 with the networkStatus issue.

Also, the docs say that:

loading: This field is true if there is currently a query fetch in flight, including after calling refetch. false otherwise.

So maybe the issue is with the docs then? FWIW I think it makes sense to have loading true anytime a query is in flight except for polling. To me, if I'm calling refetchQueries, or client.query(...), or have forceFetch: true for a query, I'm intentionally loading data from the server to keep the cache in sync - and I want my components notified anytime I'm loading data because the data they have is stale. I know that networkStatus gives finer control over how an app should react, but I see the loading value as the opportunity to set default best practices (and it seems redundant if loading is true if and only if networkStatus is 1).

All 6 comments

Note that the same issue occurs when using withApollo and calling client.query(...) directly. There is no indication that the query is loading.

Hi @rafrex. loading is only true when the component first loads, but you should be able to use networkStatus for what you want to do. In order to make the observable emit results when it changes, use notifyOnNetworkStatusChange.

Thanks @helfer, but I'm not having much luck with it. The networkStatus is always 7 for that query (with the stale data and with new data), so it doesn't seem to change. I didn't go into the details above, but the component with the query that's being refetched isn't mounted when the mutation takes place. It's only mounted on success of the mutation (with stale data from when it was previously mounted, and a networkStatus of 7, it then gets new props with the updated data, but the networkStatus is still 7).

Also, I'm using this with react-apollo.

@rafrex it should definitely change with a refetch, so that may be a bug worth filing an issue for if you have a minimal reproduction!

@helfer just opened #1263 with the networkStatus issue.

Also, the docs say that:

loading: This field is true if there is currently a query fetch in flight, including after calling refetch. false otherwise.

So maybe the issue is with the docs then? FWIW I think it makes sense to have loading true anytime a query is in flight except for polling. To me, if I'm calling refetchQueries, or client.query(...), or have forceFetch: true for a query, I'm intentionally loading data from the server to keep the cache in sync - and I want my components notified anytime I'm loading data because the data they have is stale. I know that networkStatus gives finer control over how an app should react, but I see the loading value as the opportunity to set default best practices (and it seems redundant if loading is true if and only if networkStatus is 1).

Any update about his?

Was this page helpful?
0 / 5 - 0 ratings