Skip to content
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

WIP: feat(useQuery): forward networkStatus #68

Closed
wants to merge 1 commit into from

Conversation

trojanowski
Copy link
Owner

Add networkStatus to useQuery result.
Closes #67

WIP: requires ugly hacks in suspense mode

@trojanowski
Copy link
Owner Author

Problem with the current implementation is that throwing observableQuery.result() subscribes to it (https://github.com/apollographql/apollo-client/blob/master/packages/apollo-client/src/core/ObservableQuery.ts#L156) and unsubscribes when the result is available. During the unsubscription the isTornDown flag is set (https://github.com/apollographql/apollo-client/blob/cc3706ee76c0de7d56a7936a80ec6e6b96417520/packages/apollo-client/src/core/ObservableQuery.ts#L606) which causes that the NetworkStatus.error is then returned as a value of networkStatus (https://github.com/apollographql/apollo-client/blob/cc3706ee76c0de7d56a7936a80ec6e6b96417520/packages/apollo-client/src/core/ObservableQuery.ts#L186). I was able to workaround it by creating an additional subscription (

const fakeSubscription = observableQuery.subscribe(() => {
) which is unsubscribed after the next subscription in the useEffect hook is created (
const subscription = observableQuery.subscribe(
). Unfortunately it requires to use unstable API from the scheduler package.

@trojanowski
Copy link
Owner Author

I'm closing it - networkStatus is already forwarded in the non-suspense mode. I'll try to add it to the suspense mode when Suspense for data fetching will be considered ready by the React team - maybe it'll be easier then.

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.

1 participant