[Bug] `loading` doesn't change back to false if updateQuery doesn't mutate the store
See original GitHub issueI was dealing with pagination in an app and I forgot to update my hasNextPage
field which caused a call to fetchMore
which returned an empty array (because the connection had no more edges). When I proceeded to merge this with my previous result, the loading
prop didn’t change to false
after the APOLLO_UPDATE_QUERY_RESULT
was fired.
I tried to reproduce the error by simply returning previousResult
from updateQuery
. Funnily enough, the error was only happening when I included pagination variables. This leads me to believe that the bug only occurs when APOLLO_QUERY_RESULT
changes but APOLLO_QUERY_UPDATE_RESULT
doesn’t update the store.
Here is a snippet of my code (I changed some variable names for clarity):
// repro
fetchMore({
variables: { after: connection.pageInfo.endCursor },
updateQuery: (previousResult, { fetchMoreResult: { data } }) => previousResult,
});
If variables
is removed (or after
), the bug will stop occurring. If after
is removed, but first
is added (thus changing APOLLO_QUERY_RESULT
but NOT APOLLO_UPDATE_QUERY_RESULT
) then the bug will start occurring again.
tl;dr: If updateQuery
results in a different query being fetched but it returns the previous result, loading
will never be set to false
even after both APOLLO_QUERY_RESULT
and APOLLO_QUERY_UPDATE
have been fired.
EDIT: FYI, our GraphQL backend uses the Relay Cursor Connections Specification for pagination.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Thanks, that sounds like it could be a bug. We’ll probably take care of this when we refactor the loading state in the next few weeks.
cc @tmeasday
@tmeasday, I am using
react-apollo
. Sorry for the misunderstanding.I’ve split the issue into two separate ones as needed. Closing this one.