Skip to content

WIP: feat(useQuery): forward networkStatus#68

Closed
trojanowski wants to merge 1 commit intomasterfrom
feat/forward-network-status
Closed

WIP: feat(useQuery): forward networkStatus#68
trojanowski wants to merge 1 commit intomasterfrom
feat/forward-network-status

Conversation

@trojanowski
Copy link
Copy Markdown
Owner

Add networkStatus to useQuery result.
Closes #67

WIP: requires ugly hacks in suspense mode

@trojanowski
Copy link
Copy Markdown
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 trojanowski force-pushed the feat/forward-network-status branch from 92c910f to 704fc9a Compare February 1, 2019 18:40
@trojanowski
Copy link
Copy Markdown
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