feat(repos): 添加订阅commit log 接口。
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user