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

On reset store and allow ignore fragments on removeDirectives #3010

Merged
merged 15 commits into from
Mar 13, 2018

Conversation

akiran
Copy link
Contributor

@akiran akiran commented Feb 14, 2018

Fix test issues of #2843

@apollo-cla
Copy link

apollo-cla commented Feb 27, 2018

Messages
📖

Please add your name and email to the AUTHORS file (optional)

Generated by 🚫 dangerJS

@evans evans force-pushed the on-reset-store branch 2 times, most recently from 0ab8e63 to d1e2735 Compare March 9, 2018 01:01
@evans evans changed the title On reset store On reset store and allow ignore fragments on removeDirectives Mar 9, 2018
@evans
Copy link
Contributor

evans commented Mar 9, 2018

Currently this splits resetStore into two steps: clearStore and reFetchObservableQueries. The reason to do this is to have the onResetStore callbacks run when the store is empty.

The problem with this split as a simple implementation is this error is used to reject the in-flight queries. When the promise representing the in-flight query is rejected, this code path for notifying the observableQuery of an error is invoked. If the query is not told to be refetched before that code, then a check for a new request fails. The in-flight error is then passed to the observableQuery, which notifies the observableQuery of the error.

The current implementation of apollo-client invokes getObservableQueryPromises, refetching all observable queries, in the same function/event step as the in-flight error rejection, so on the next promise step when the catch call for the in-flight error runs and sees that another query is in-flight, so it does not notify the observableQuery of the error.

The question then is how should clearStore behave. There are two options after clearing the store: refetch the observableQueries after the store is cleared and return promises representing the result of these fetches OR simply suspend the observableQueries, preventing them from notifying.

I think clearStore should not start the observableQuery refetch, since there would be a race condition between when finish their fetch and the onResetStore callbacks. This means that we need to have a way of suspending the observableQueries. These changes increase the lastRequestId in order to prevent the in-flight error from notifying, essentially simulating that a refetch is occurring without actually refetching. The other option is to create a networkStatus that pauses the observableQuery notification.

Another thing to note is the promise representing the fetch is garbage collected after the error has notified, so an other option of not erroring on an observableQuery when the store is reset would need to take that into account

@ghost ghost added the feature label Mar 9, 2018
Copy link
Contributor

@peggyrayzis peggyrayzis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @akiran, @evans, and @jbaxleyiii for all your work on this PR!! So excited to finally squash this bug :shipit:

@peggyrayzis peggyrayzis merged commit b7fe71e into apollographql:master Mar 13, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants