QueryBus
Defined in: packages/cqrs/src/query.bus.ts:18
Sends a query to its one handler, through the handler’s pipeline. createCqrs()
builds it.
Example
Section titled “Example”const { queryBus } = createCqrs();const user = await queryBus.execute<GetUserQuery, User | null>(new GetUserQuery('u-1'));Type Parameters
Section titled “Type Parameters”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new QueryBus<
Q>(handlers):QueryBus<Q>
Defined in: packages/cqrs/src/query.bus.ts:24
Parameters
Section titled “Parameters”handlers
Section titled “handlers”ReadonlyMap<AnyClass, Dispatch>
Maps each query class to the function that runs its handler. The bus reads it at every call, so it can be filled after the bus is created, as handlers that inject the bus require.
Returns
Section titled “Returns”QueryBus<Q>
Methods
Section titled “Methods”execute()
Section titled “execute()”execute<
T,R>(query):Promise<R>
Defined in: packages/cqrs/src/query.bus.ts:37
Runs the handler of the query’s class, or of its nearest parent class that has
one, and resolves with what the handler returns, typed as R.
Type Parameters
Section titled “Type Parameters”T extends IQuery
R = unknown
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”Promise<R>
Throws
Section titled “Throws”QueryHandlerNotFoundException (as a rejection) when no class in the query’s chain has a handler.
Example
Section titled “Example”await queryBus.execute(new GetUserQuery('u-1'));