Skip to content

Support ApolloClient#stop for safe client disposal.#4336

Merged
benjamn merged 5 commits intomasterfrom
support-ApolloClient-stop-method
Jan 18, 2019
Merged

Support ApolloClient#stop for safe client disposal.#4336
benjamn merged 5 commits intomasterfrom
support-ApolloClient-stop-method

Conversation

@benjamn
Copy link
Copy Markdown
Member

@benjamn benjamn commented Jan 18, 2019

Inspired by apollographql/react-apollo#2738, it should be possible to shut down an ApolloClient instance without making assumptions about its implementation details.

This client.stop() method should also be useful for server-side rendering, where you're supposed to create (and throw away) a new ApolloClient instance for each request.

I'm not entirely sure this implementation cleans up everything that might need to be cleaned up, but I am sure it's better than nothing.

Inspired by apollographql/react-apollo#2738, it
should be possible to shut down an ApolloClient instance without making
assumptions about its implementation details.

This client.stop() method should also be useful for server-side rendering,
where you're supposed to create (and throw away) a new ApolloClient
instance for each request.

I'm not entirely sure this implementation cleans up everything that might
need to be cleaned up, but I am sure it's better than nothing.
@benjamn benjamn self-assigned this Jan 18, 2019
@benjamn benjamn requested a review from hwillson January 18, 2019 23:14
@benjamn
Copy link
Copy Markdown
Member Author

benjamn commented Jan 18, 2019

cc @rosskevin @danilobuerger

Copy link
Copy Markdown
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Looks great @benjamn! This should definitely help. I know we're moving quick to address apollographql/react-apollo#2738, but we'll want to circle back here to get some tests and API docs changes in place. I'll make a note. Thanks!

@benjamn benjamn merged commit 9d03151 into master Jan 18, 2019
@benjamn benjamn deleted the support-ApolloClient-stop-method branch January 18, 2019 23:53
benjamn added a commit to apollographql/react-apollo that referenced this pull request Jan 19, 2019
benjamn added a commit that referenced this pull request Jan 19, 2019
This reverts commit 9739ff6.

Now that we have a uniform interface for terminating ApolloClient
instances (#4336), there should be no need for any external code to access
the QueryScheduler abstraction, which this commit removes.

We should wait to merge and release this change until after
apollographql/react-apollo#2741 has been merged
and released, so that we don't break older versions of MockedProvider.
// After calling this.stopPollingQuery for all registered queries, calling
// fetchQueriesOnInterval will remove the corresponding intervals.
Object.keys(this.intervalQueries).forEach(interval => {
this.fetchQueriesOnInterval(+interval);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@benjamn Why is there a + before interval?

@danilobuerger
Copy link
Copy Markdown
Contributor

Awesome!

benjamn added a commit to apollographql/react-apollo that referenced this pull request Jan 19, 2019
benjamn added a commit that referenced this pull request Jan 22, 2019
This reverts commit 9739ff6.

Now that we have a uniform interface for terminating ApolloClient
instances (#4336), there should be no need for any external code to access
the QueryScheduler abstraction, which this commit removes.

We should wait to merge and release this change until after
apollographql/react-apollo#2741 has been merged
and released, so that we don't break older versions of MockedProvider.
benjamn added a commit that referenced this pull request Jan 22, 2019
This reverts commit 9739ff6.

Now that we have a uniform interface for terminating ApolloClient
instances (#4336), there should be no need for any external code to access
the QueryScheduler abstraction, which this commit removes.

We should wait to merge and release this change until after
apollographql/react-apollo#2741 has been merged
and released, so that we don't break older versions of MockedProvider.
@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.

3 participants