Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 459d205

Browse files
feat: updated approach to load preferences
1 parent a3b021f commit 459d205

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

‎src/app.module.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from 'path';
22
import { Module } from '@nestjs/common';
3-
import { ConfigModule } from '@nestjs/config';
3+
import { ConfigModule,ConfigService } from '@nestjs/config';
44
import { GraphQLModule } from '@nestjs/graphql';
55
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
66
import config from './config';
@@ -11,11 +11,15 @@ import { SampleModule } from './sample/sample.module';
1111
controllers: [AppController],
1212
imports: [
1313
ConfigModule.forRoot({ isGlobal: true, load: [config] }),
14-
GraphQLModule.forRoot<ApolloDriverConfig>({
14+
GraphQLModule.forRootAsync<ApolloDriverConfig>({
1515
driver: ApolloDriver,
16-
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
17-
debug: true,
18-
playground: true,
16+
imports: [ConfigModule],
17+
useFactory: async (configService: ConfigService) => ({
18+
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
19+
debug: configService.get('graphql').debug,
20+
playground: configService.get('graphql').playground,
21+
}),
22+
inject: [ConfigService],
1923
}),
2024
SampleModule,
2125
],

‎src/config.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
export type Config = {
22
port?: number;
3+
graphql?: {
4+
debug?: boolean;
5+
playground?: boolean;
6+
};
37
}
48

59
// Define environment variables
610
export default () => ({
711
port: process.env.PORT || 3000,
12+
graphql: {
13+
debug: process.env.GRAPHQL_DEBUG || false,
14+
playground: process.env.GRAPHQL_PLAYGROUND || false,
15+
},
816
} as Config);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /