Skip to content

Commit

Permalink
refactor(): stop apollo server on module destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslav-kuts committed Sep 10, 2020
1 parent c121c5a commit b288acd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Inject, Module } from '@nestjs/common';
import {
DynamicModule,
OnModuleInit,
OnModuleDestroy,
Provider,
} from '@nestjs/common/interfaces';
import { loadPackage } from '@nestjs/common/utils/load-package.util';
Expand Down Expand Up @@ -48,7 +49,7 @@ import {
],
exports: [GraphQLTypesLoader, GraphQLAstExplorer, GraphQLSchemaHost],
})
export class GraphQLModule implements OnModuleInit {
export class GraphQLModule implements OnModuleInit, OnModuleDestroy {
protected apolloServer: ApolloServerBase;
constructor(
private readonly httpAdapterHost: HttpAdapterHost,
Expand Down Expand Up @@ -154,6 +155,10 @@ export class GraphQLModule implements OnModuleInit {
}
}

async onModuleDestroy() {
this.apolloServer.stop();
}

private registerGqlServer(apolloOptions: GqlModuleOptions) {
const httpAdapter = this.httpAdapterHost.httpAdapter;
const platformName = httpAdapter.getType();
Expand Down

0 comments on commit b288acd

Please sign in to comment.