Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/graphql/lib/graphql.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Inject, Logger, Module, RequestMethod } from '@nestjs/common';
import {
DynamicModule,
OnApplicationShutdown,
OnModuleDestroy,
OnModuleInit,
Provider,
Expand Down Expand Up @@ -55,7 +56,7 @@ import { extend, generateString } from './utils';
export class GraphQLModule<
TAdapter extends AbstractGraphQLDriver = AbstractGraphQLDriver,
>
implements OnModuleInit, OnModuleDestroy
implements OnModuleInit, OnModuleDestroy, OnApplicationShutdown
{
public completeOptions: GqlModuleOptions | undefined;
private static readonly logger = new Logger(GraphQLModule.name, {
Expand All @@ -76,7 +77,15 @@ export class GraphQLModule<
) {}

async onModuleDestroy() {
await this._graphQlAdapter.stop();
if (!this.options.stopOnApplicationShutdown) {
await this._graphQlAdapter.stop();
}
}

async onApplicationShutdown() {
if (this.options.stopOnApplicationShutdown) {
await this._graphQlAdapter.stop();
}
}

static forRoot<TOptions extends Record<string, any> = GqlModuleOptions>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ export interface GqlModuleOptions<TDriver extends GraphQLDriver = any> {
* @default true
*/
introspection?: boolean;

/**
* If `true`, the GraphQL server will stop during `onApplicationShutdown`
* instead of `onModuleDestroy`. This allows the server to keep accepting
* requests during `beforeApplicationShutdown`, enabling graceful shutdown.
* @default false
*/
stopOnApplicationShutdown?: boolean;
}

export interface GqlOptionsFactory<
Expand Down