Skip to content

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

typescript
// 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

ts
new GraphQLPubSubModule(): GraphQLPubSubModule;

Returns

GraphQLPubSubModule

Methods

forRoot()

ts
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

ParameterType
optionsGraphQLPubSubModuleOptions

Returns

typeof GraphQLPubSubModuleCore


forRootAsync()

ts
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

ParameterType
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

typescript
GraphQLPubSubModule.forRootAsync({
  inject: [ConfigService],
  useFactory: async (config: ConfigService) => ({
    connection: { host: await config.getRedisHost(), port: 6379 },
  }),
});

Released under the MIT License.