SyncedQuery() function
Home > @cbnsndwch/nest-zero-synced-queries > SyncedQuery
SyncedQuery() function
Decorator for Zero synced query handlers.
Use this decorator to mark a method as a synced query handler. Works on both controllers and providers.
Signature:
export declare function SyncedQuery(
queryName: string,
inputSchema: z.ZodTypeAny
): MethodDecorator;Parameters
Parameter
Type
Description
queryName
string
The name of the query as registered with Zero
inputSchema
z.ZodTypeAny
Zod schema for validating input arguments
Returns:
MethodDecorator
Remarks
The method signature can use any NestJS parameter decorators you want. Use @QueryArg(index) to explicitly map query arguments by position.
Example
// Public query (no authentication)
@SyncedQuery('publicChannels', z.tuple([]))
async publicChannels() {
return builder.channels.where('isPublic', '=', true);
}
// Authenticated query (use your own guards and decorators)
@UseGuards(JwtAuthGuard)
@SyncedQuery('myChats', z.tuple([]))
async myChats(@CurrentUser() user: JwtPayload) {
return builder.chats.where('userId', '=', user.sub);
}
// Query with arguments
@SyncedQuery('channelById', z.tuple([z.string()]))
async channelById(@QueryArg(0) channelId: string) {
return builder.channels.where('_id', '=', channelId);
}How was this page?