uncaughtException:无法确定“expectedInvestmentSupportInfo”的 GraphQL 输出类型

问题描述 投票:0回答:1

我创建了一个名为

UploadedInvestmentDocumentInput
的 DTO 并将其附加到
expectedInvestmentSupportInfo
属性,但出现以下错误:-

uncaughtException: Cannot determine a GraphQL output type for the "expectedInvestmentSupportInfo".

 Make sure your class is decorated with an appropriate decorator.
Error: Cannot determine a GraphQL output type for the "expectedInvestmentSupportInfo". 
Make sure your class is decorated with an appropriate decorator.

机会帐户.input.ts

import { UploadedDocumentInput } from '@app/dto/common.input';
import {
  Field,
  InputType, OmitType, PickType, registerEnumType,
} from '@nestjs/graphql';
import { Type } from 'class-transformer';
import { IsEnum, ValidateNested } from 'class-validator';

import {
  ExpectedInvestmentSupportInfoType,
  SourceOfFundsType,
} from '@/generated-cbms-api-client';

import { OpportunityAccount } from './opportunity-account.response';

registerEnumType(SourceOfFundsType, { name: 'SourceOfFundsType' });
registerEnumType(ExpectedInvestmentSupportInfoType, { name: 'ExpectedInvestmentSupportInfoType' });

@InputType()
export class UploadedInvestmentDocumentInput extends OmitType(UploadedDocumentInput, ['documentType'], InputType) {
  @IsEnum(ExpectedInvestmentSupportInfoType)
  @Field(() => ExpectedInvestmentSupportInfoType)
  documentType: ExpectedInvestmentSupportInfoType;
}

@InputType()
export class UpsertAnticipatedInvestmentActivitiesInput extends PickType(
  OpportunityAccount,
  [
    'isPlanningInvestIn12Months',
    'anticipatedInvestmentOpportunitiesCountRange',
    'investmentDescription',
  ],
  InputType,
) {
  @ValidateNested({ each: true })
  @Type(() => UploadedInvestmentDocumentInput)
  @Field(() => [UploadedInvestmentDocumentInput], { description: 'Expected investment support info' })
  expectedInvestmentSupportInfo: UploadedInvestmentDocumentInput[];
}

UploadedDocumentInput(普通DTO)

import { Field, InputType } from '@nestjs/graphql';
import { FileUpload, GraphQLUpload } from 'graphql-upload';

@InputType()
export class UploadedDocumentInput {
  @Field(() => Number)
  documentType: number;

  @Field(() => GraphQLUpload)
  frontSideDoc: FileUpload;

  @Field(() => GraphQLUpload, { nullable: true })
  backSideDoc?: FileUpload;
}

机会帐户.output.ts

class UploadedInvestmentDocumentResponse extends OmitType(UploadedDocumentResponse, ['documentType'], InputType) {
  @IsEnum(ExpectedInvestmentSupportInfoType)
  @Field(() => ExpectedInvestmentSupportInfoType)
  documentType: ExpectedInvestmentSupportInfoType;
}

@ObjectType()
export class OpportunityAccount extends AccountsCommonDetails {
  @IsMongoId()
  @Field(() => String, { description: 'Customer id' })
  customerId: string;

// I believe issue is here ( when I commented out the field below, this error vanished !)

  @IsEnum(UploadedInvestmentDocumentResponse)
  @ValidateNested({ each: true })
  @Type(() => UploadedInvestmentDocumentResponse)
  @Field(() => [UploadedInvestmentDocumentResponse], { description: 'Expected investment support info' })
  expectedInvestmentSupportInfo: UploadedInvestmentDocumentResponse[];

 

}

由于我收到上述错误,我缺少什么装饰器或属性?

javascript typescript graphql nestjs dto
1个回答
1
投票

我必须将

ObjectType
装饰器添加到
UploadedInvestmentDocumentResponse
并从
InputType 
中删除
OmitType(UploadedDocumentResponse, ['documentType'])
,因为我正在创建一个绑定到响应字段而不是输入字段的对象!

机会帐户.output.ts

@ObjectType()
class UploadedInvestmentDocumentResponse extends OmitType(UploadedDocumentResponse, ['documentType']) {
  @IsEnum(ExpectedInvestmentSupportInfoType)
  @Field(() => ExpectedInvestmentSupportInfoType)
  documentType: ExpectedInvestmentSupportInfoType;
}

@ObjectType()
export class OpportunityAccount extends AccountsCommonDetails {
  @IsMongoId()
  @Field(() => String, { description: 'Customer id' })
  customerId: string;

// I believe issue is here ( when I commented out the field below, this error vanished !)

  @IsEnum(UploadedInvestmentDocumentResponse)
  @ValidateNested({ each: true })
  @Type(() => UploadedInvestmentDocumentResponse)
  @Field(() => [UploadedInvestmentDocumentResponse], { description: 'Expected investment support info' })
  expectedInvestmentSupportInfo: UploadedInvestmentDocumentResponse[];

 

}
© www.soinside.com 2019 - 2024. All rights reserved.