Function: OnQuery()
ts
function OnQuery(type: QueryType): MethodDecorator;Defined in: src/wirestate-core/queries/on-query.ts:38
Marks a service method as a query handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | QueryType | Query token. |
Returns
MethodDecorator
Method decorator.
Remarks
The handler registers when the service activates and unregisters when the service deactivates.
Queries answer reads. If several handlers use the same token, the newest one answers. Think stack of sticky notes: read the top note first.
Example
typescript
import { Injectable, OnQuery } from "@wirestate/core";
@Injectable()
class UserProfileService {
@OnQuery("GET_USER_AVATAR")
private async onGetUserAvatar(userId: string): Promise<string> {
const user: User = await this.userRepository.findById(userId);
return user.avatarUrl;
}
}