import { Resolver, Args, Mutation, Subscription, Query } from '@nestjs/graphql'; import { PipelineTask } from './pipeline-task.entity'; import { PipelineTasksService } from './pipeline-tasks.service'; import { CreatePipelineTaskInput } from './dtos/create-pipeline-task.input'; import { PipelineTaskLogMessage } from './models/pipeline-task-log-message.module'; import { PipelineTaskLogArgs } from './dtos/pipeline-task-log.args'; import { PipelineTaskLogsService } from './pipeline-task-logs.service'; @Resolver() export class PipelineTasksResolver { constructor( private readonly service: PipelineTasksService, private readonly logsService: PipelineTaskLogsService, ) {} @Mutation(() => PipelineTask) async createPipelineTask(@Args('task') taskDto: CreatePipelineTaskInput) { return await this.service.addTask(taskDto); } @Subscription(() => PipelineTaskLogMessage, { resolve: (value) => { return value; }, }) async pipelineTaskLog(@Args() args: PipelineTaskLogArgs) { const task = await this.service.findTaskById(args.taskId); const asyncIterator = this.logsService.watchLogs(task); return asyncIterator; } @Subscription(() => PipelineTask, { resolve: (value) => { return value; }, }) async pipelineTaskChanged(@Args('id') id: string) { return await this.service.watchTaskUpdated(id); } @Query(() => [PipelineTask]) async listPipelineTaskByPipelineId(@Args('pipelineId') pipelineId: string) { return await this.service.listTasksByPipelineId(pipelineId); } @Query(() => PipelineTask) async findPipelineTask(@Args('id') id: string) { return await this.service.findTaskById(id); } }