-
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
Add networkStatus
to queries.
#707
Comments
@tmeasday this is super interesting! First thought is I like the direction and someone can always ignore it when creating custom props if they want. Let me think about it and I'll get you a full response later today! |
See: #690 |
Some implementation notes: https://paper.dropbox.com/doc/Plan-for-networkStatus-aGMicsJoswscqscEW7M4l |
@tmeasday This is not done yet right? |
I think @helfer just shipped it actually: https://github.com/apollostack/apollo-client/blob/master/CHANGELOG.md#v050-preview3 But it doesn't yet trigger subscriber changes on every network status change unless you request it, I think. |
Yeah, it's what's in #827. Not yet updated in react-apollo. |
Currently, in the store, queries have two fields that indicate their current "network status":
loading: true/false
: is there a network event attached to this query.returnPartialData: true/false
: is there some data to return from this query (and does the query want it)?Problems with this:
loading: true
states. Users should be able to read directly from the store and see results w/ the same shape as the subscription IMO.returnPartialData
is, given you can just checkobservable.options.returnPartialData
at read time if you care. (If you are looking at the store and wondering what the network status of the query is, this doesn't tell you anything as the query is probably fetching anyway).i. There may be a case for a
queryStoreValue.resultsIncomplete
in thenoFetch
case however, to tell the user that even though the query isn't loading, the results aren't all there.Proposed solution:
Add
queryStoreValue.networkStatus
and be explicit about what's happening for a query.A key insight is there can be only one network event per query at any time, so there is a precedence to these, and they should clobber each other[1]
loading
- the query is loading for the first time.setVariables
- the variables of the query have changed, the current results are for the old query.fetchMore
- we are 'fetching more' for this queryrefetch
- we are refetchingpoll
- we are pollingready
- all data is here. We good. [edit]We should publish
networkStatus
fairly transparently, clean up the behavior of theloading
flag, and remove thereturnPartialResults
flag.Potential objections:
During the
setVariables
network event we should not return the old query results (from the subscription event orobservable.currentResult()
)I'm on the fence about this one. It's the current behavior of
react-apollo
and it helps in some use cases, but it doesn't really feel "correct". cc AddobservableQuery
setVariables
#635It becomes a little more tricky to know if the query should return partial results, but I think this is fine.
Consequences for
react-apollo
and other integrationsIf RA passes
{ loading, networkStatus, currentResult }
straight through (more or less), then the behavior will change as follows:loading
will no longer betrue
during during refetches. HowevernetworkStatus: refetch
will be true. Alternatively the user can use external state + the promise result to track the refetch progress.currentResult
will be empty during asetVariables
event. This is why I'm inclined to leave the behavior of AddobservableQuery
setVariables
#635 and make it the old query's result.@jbaxleyiii double checking with you that the above makes sense?
[1] By this I mean if a higher precedence network event fires, it should cancel the existing event, and if a lower precedence event fires it should just be a no-op.
The text was updated successfully, but these errors were encountered: