Assuming based on the year this question was asked that you are asking about ApolloServer v2. Apollo Server instance does provide stop
function which as per documentation waits for all the background tasks running. So it will wait for existing queries to complete before terminating the server. The method is available for v3 as well.
ApolloServer.stop()
is an async method that tells all of Apollo
Server's background tasks to complete. It calls and awaits all
serverWillStop
plugin
handlers
(including the usage reporting
plugin's
handler, which sends a final usage report to Apollo Studio). This
method takes no arguments.
If your server is a federated
gateway,
stop
also stops gateway-specific background activities, such as
polling for updated service configuration.
In some circumstances, Apollo Server calls stop
automatically when
the process receives a SIGINT
or SIGTERM
signal. See the
stopOnTerminationSignals
constructor
option
for details.
If you're using the apollo-server
package (which handles setting up
an HTTP server for you), this method first stops the HTTP server.
Specifically, it:
- Stops listening for new connections
- Closes idle connections (i.e., connections with no current HTTP request)
- Closes active connections whenever they become idle
- Waits for all connections to be closed
If any connections remain active after a grace period (10 seconds by
default), Apollo Server forcefully closes those connections. You can
configure this grace period with the stopGracePeriodMillis
constructor
option.
If you're using a middleware
package
instead of apollo-server
, you should stop your HTTP server before
calling ApolloServer.stop()
.