feat(repos): 添加订阅commit log 接口。

This commit is contained in:
Ivan
2021-03-08 11:26:12 +08:00
parent ba0ba46a35
commit 22d3dc299c
6 changed files with 60 additions and 29 deletions

View File

@ -1,26 +1,17 @@
import { Args, Query, Resolver } from '@nestjs/graphql';
import { ListLogsArgs } from './dtos/list-logs.args';
import { ReposService } from './repos.service';
import { LIST_LOGS_DONE, LIST_LOGS_PUB_SUB } from './repos.constants';
import { Resolver, Subscription } from '@nestjs/graphql';
import { LogList } from './dtos/log-list.model';
import { ListBranchesArgs } from './dtos/list-branches.args';
import { BranchList } from './dtos/branch-list.model';
import { Inject } from '@nestjs/common';
import { PubSub } from 'apollo-server-express';
@Resolver()
export class ReposResolver {
constructor(private readonly service: ReposService) {}
@Query(() => LogList)
async listLogs(@Args('listLogsArgs') dto: ListLogsArgs) {
return await this.service.listLogs(dto);
}
@Query(() => BranchList)
async listBranches(
@Args('listBranchesArgs') dto: ListBranchesArgs,
): Promise<BranchList> {
return await this.service.listBranches(dto).then((data) => {
return {
...data,
branches: Object.values(data.branches),
};
});
constructor(
@Inject(LIST_LOGS_PUB_SUB)
private readonly pubSub: PubSub,
) {}
@Subscription(() => LogList)
listLogsDone() {
return this.pubSub.asyncIterator(LIST_LOGS_DONE);
}
}