fix: Graphql 类型报错

This commit is contained in:
Ivan Li 2021-03-06 12:24:20 +08:00
parent 38d3cb0db8
commit 0dadc09ec5
8 changed files with 28 additions and 20 deletions

View File

@ -1,4 +1,4 @@
import { InputType } from '@nestjs/graphql'; import { Field, InputType } from '@nestjs/graphql';
import { PipelineUnits } from '../enums/pipeline-units.enum'; import { PipelineUnits } from '../enums/pipeline-units.enum';
@InputType() @InputType()
@ -7,5 +7,6 @@ export class CreatePipelineTaskInput {
commit: string; commit: string;
@Field(() => PipelineUnits)
units: PipelineUnits[]; units: PipelineUnits[];
} }

View File

@ -1,3 +1,5 @@
import { registerEnumType } from '@nestjs/graphql';
export enum PipelineUnits { export enum PipelineUnits {
checkout = 'checkout', checkout = 'checkout',
installDependencies = 'installDependencies', installDependencies = 'installDependencies',
@ -5,3 +7,8 @@ export enum PipelineUnits {
deploy = 'deploy', deploy = 'deploy',
cleanUp = 'cleanUp', cleanUp = 'cleanUp',
} }
registerEnumType(PipelineUnits, {
name: 'PipelineUnits',
description: '流水线单元',
});

View File

@ -1,5 +1,8 @@
import { InputType, ObjectType } from '@nestjs/graphql';
import { WorkUnit } from './work-unit.model'; import { WorkUnit } from './work-unit.model';
@InputType('WorkUnitMetadataInput')
@ObjectType()
export class WorkUnitMetadata { export class WorkUnitMetadata {
version = 1; version = 1;
units: WorkUnit[]; units: WorkUnit[];

View File

@ -1,6 +1,13 @@
import { PipelineUnits as PipelineUnitTypes } from '../enums/pipeline-units.enum'; import { Field, InputType, ObjectType } from '@nestjs/graphql';
import {
PipelineUnits,
PipelineUnits as PipelineUnitTypes,
} from '../enums/pipeline-units.enum';
@ObjectType()
@InputType('WorkUnitInput')
export class WorkUnit { export class WorkUnit {
@Field(() => PipelineUnits)
type: PipelineUnitTypes; type: PipelineUnitTypes;
scripts: string[]; scripts: string[];
} }

View File

@ -1,6 +1,7 @@
import { InputType } from '@nestjs/graphql'; import { InputType } from '@nestjs/graphql';
import { WorkUnitMetadata } from '../../pipeline-tasks/models/work-unit-metadata.model';
import { import {
IsObject, IsInstance,
IsOptional, IsOptional,
IsString, IsString,
IsUUID, IsUUID,
@ -21,6 +22,6 @@ export class CreatePipelineInput {
name: string; name: string;
@IsOptional() @IsOptional()
@IsObject() @IsInstance(WorkUnitMetadata)
workUnitMetadata = {}; workUnitMetadata: WorkUnitMetadata;
} }

View File

@ -9,7 +9,7 @@ import { ListPipelineArgs } from './dtos/list-pipelines.args';
export class PipelinesResolver { export class PipelinesResolver {
constructor(private readonly service: PipelinesService) {} constructor(private readonly service: PipelinesService) {}
@Query(() => [Pipeline]) @Query(() => [Pipeline])
async findPipelines(@Args('listPipelineArgs') dto: ListPipelineArgs) { async findPipelines(@Args() dto: ListPipelineArgs) {
return await this.service.list(dto); return await this.service.list(dto);
} }

View File

@ -4,7 +4,7 @@ import { IsOptional, IsString, IsUUID } from 'class-validator';
@InputType() @InputType()
export class CheckoutInput { export class CheckoutInput {
@IsUUID() @IsUUID()
projectId: string; pipelineId: string;
@IsString() @IsString()
@IsOptional() @IsOptional()

View File

@ -1,18 +1,13 @@
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; import { Args, Query, Resolver } from '@nestjs/graphql';
import { ListLogsArgs } from './dtos/list-logs.args'; import { ListLogsArgs } from './dtos/list-logs.args';
import { ReposService } from './repos.service'; import { ReposService } from './repos.service';
import { LogList } from './dtos/log-list.model'; import { LogList } from './dtos/log-list.model';
import { ListBranchesArgs } from './dtos/list-branches.args'; import { ListBranchesArgs } from './dtos/list-branches.args';
import { BranchList } from './dtos/branch-list.model'; import { BranchList } from './dtos/branch-list.model';
import { CheckoutInput } from './dtos/checkout.input';
import { ProjectsService } from '../projects/projects.service';
@Resolver() @Resolver()
export class ReposResolver { export class ReposResolver {
constructor( constructor(private readonly service: ReposService) {}
private readonly service: ReposService,
private readonly projectService: ProjectsService,
) {}
@Query(() => LogList) @Query(() => LogList)
async listLogs(@Args('listLogsArgs') dto: ListLogsArgs) { async listLogs(@Args('listLogsArgs') dto: ListLogsArgs) {
return await this.service.listLogs(dto); return await this.service.listLogs(dto);
@ -28,10 +23,4 @@ export class ReposResolver {
}; };
}); });
} }
@Mutation(() => Boolean)
async checkout(@Args('checkoutInput') dto: CheckoutInput): Promise<true> {
const project = await this.projectService.findOne(dto.projectId);
await this.service.checkoutCommit(project, dto.commitNumber);
return true;
}
} }