Class: GraphQLPubSubModule
Defined in: packages/graphql-pubsub/src/graphql-pubsub.module.ts:107
Feature module that provides a RedisPubSub instance for use with GraphQL subscriptions.
Register it once at the root level using forRoot or forRootAsync, then inject the instance anywhere with @Inject(GRAPHQL_PUBSUB) or the InjectPubSub shortcut.
Example
// Synchronous — static Redis options
@Module({
imports: [
GraphQLPubSubModule.forRoot({
useValue: { connection: { host: "localhost", port: 6379 } },
}),
],
})
export class AppModule {}
// Asynchronous — derive options from another provider
@Module({
imports: [
GraphQLPubSubModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
connection: { host: config.get("REDIS_HOST"), port: 6379 },
}),
}),
],
})
export class AppModule {}Constructors
Constructor
new GraphQLPubSubModule(): GraphQLPubSubModule;Returns
GraphQLPubSubModule
Methods
forRoot()
static forRoot(options?): typeof GraphQLPubSubModuleCore;Defined in: packages/graphql-pubsub/src/graphql-pubsub.module.ts:114
Registers the module with a synchronous configuration.
The returned class is decorated with @Global by default (override with isGlobal: false).
Parameters
| Parameter | Type |
|---|---|
options | GraphQLPubSubModuleOptions |
Returns
typeof GraphQLPubSubModuleCore
forRootAsync()
static forRootAsync(options): typeof GraphQLPubSubModuleCore;Defined in: packages/graphql-pubsub/src/graphql-pubsub.module.ts:172
Registers the module with an asynchronous configuration.
The useFactory is resolved once by the DI container and its result is stored under the GRAPHQL_PUBSUB_OPTIONS token. The GRAPHQL_PUBSUB provider then receives the resolved options as its first argument.
Parameters
| Parameter | Type |
|---|---|
options | { inject?: ProviderToken[]; isGlobal?: boolean; useFactory: (...args) => | RedisPubSubOptions | Promise<RedisPubSubOptions>; } |
options.inject? | ProviderToken[] |
options.isGlobal? | boolean |
options.useFactory | (...args) => | RedisPubSubOptions | Promise<RedisPubSubOptions> |
Returns
typeof GraphQLPubSubModuleCore
Example
GraphQLPubSubModule.forRootAsync({
inject: [ConfigService],
useFactory: async (config: ConfigService) => ({
connection: { host: await config.getRedisHost(), port: 6379 },
}),
});