Skip to content

Commit

Permalink
Replace use of upstream with the fork
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser committed Jul 23, 2021
1 parent 08cada0 commit 26ac42c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 63 deletions.
70 changes: 19 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"@types/qs-middleware": "1.0.1",
"@types/request": "2.48.6",
"@types/request-promise": "4.1.48",
"@types/stoppable": "1.1.1",
"@types/supertest": "2.0.11",
"@types/test-listen": "1.1.0",
"@types/type-is": "1.6.3",
Expand Down
3 changes: 1 addition & 2 deletions packages/apollo-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"dependencies": {
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-express": "file:../apollo-server-express",
"express": "^4.17.1",
"stoppable": "^1.1.0"
"express": "^4.17.1"
},
"devDependencies": {
"apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite"
Expand Down
24 changes: 15 additions & 9 deletions packages/apollo-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
// instead.
import express from 'express';
import http from 'http';
import stoppable from 'stoppable';
import {
ApolloServer as ApolloServerExpress,
CorsOptions,
ApolloServerExpressConfig,
} from 'apollo-server-express';
import type { AddressInfo } from 'net';
import { format as urlFormat } from 'url';
import { makeHttpServerStopper } from './stoppable';

export * from './exports';

Expand All @@ -25,7 +25,7 @@ export interface ServerInfo {
}

export class ApolloServer extends ApolloServerExpress {
private httpServer?: stoppable.StoppableServer;
private stopper?: () => Promise<boolean>;
private cors?: CorsOptions | boolean;
private onHealthCheck?: (req: express.Request) => Promise<any>;
private stopGracePeriodMillis: number;
Expand Down Expand Up @@ -108,17 +108,21 @@ export class ApolloServer extends ApolloServerExpress {
});

const httpServer = http.createServer(app);
// `stoppable` adds a `.stop()` method which:

// `makeHttpServerStopper` returns an async function which:
// - closes the server (ie, stops listening)
// - closes all connections with no active requests
// - continues to close connections when their active request count drops to
// zero
// - in 10 seconds (configurable), closes all remaining active connections
// - calls its callback once there are no remaining active connections
// - returns (async) once there are no remaining active connections
//
// If you don't like this behavior, use apollo-server-express instead of
// apollo-server.
this.httpServer = stoppable(httpServer, this.stopGracePeriodMillis);
this.stopper = makeHttpServerStopper(
httpServer,
this.stopGracePeriodMillis,
);

await new Promise((resolve) => {
httpServer.once('listening', resolve);
Expand All @@ -132,10 +136,12 @@ export class ApolloServer extends ApolloServerExpress {
}

public override async stop() {
if (this.httpServer) {
const httpServer = this.httpServer;
await new Promise<void>((resolve) => httpServer.stop(() => resolve()));
this.httpServer = undefined;
// First drain the HTTP server. (See #5074 for a plan to generalize this to
// the web framework integrations.)
const { stopper } = this;
if (stopper) {
this.stopper = undefined;
await stopper();
}
await super.stop();
}
Expand Down

0 comments on commit 26ac42c

Please sign in to comment.