Skip to content

Module Options

Alex Ald edited this page May 2, 2019 · 7 revisions

Options

  • pgConfig (required): An object or string that will be passed to the pg library and used to connect to a PostgreSQL backend, OR a pg.Pool to use.
  • schema (optional): A string, or array of strings, which specifies the PostgreSQL schema(s) you choose to expose via PostGraphile (Defaults to 'public')
  • playground (optional): set this to true to enable the Playground interface (Defaults to false)
  • playgroundRoute (optional): override the playground's route (Defaults to /playground)

NOTE: Visit PostGraphile's documentation to see additional configuration options that can be set.

Setting Options on Module

Adding PostGraphile configuration to your Nest application

@Module({
  imports: [
    PostGraphileModule.forRoot({
      pgConfig: process.env.DATABASE_URL,
    })
  ]
})
export class AppModule {}

Use a factory to set module options

@Module({
  imports: [
    ConfigModule,
    PostGraphileModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          pgConfig: configService.get('GRAPHILE_URL'),
          schema: configService.get('DATABASE_SCHEMA').split(','),
        };
      },
    }),
  ],
})
export class AppModule {}