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

31 views Asked by At

I have created a DTO called UploadedInvestmentDocumentInput and have attached it to the expectedInvestmentSupportInfo property but I am getting the following error:-

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.

opportunity-account.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 ( common 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;
}

opportunity-account.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[];

 

}

What decorator or property am I missing due to which I am getting the above mentioned error ?

1

There are 1 answers

0
Abdullah Ch On

I had to add ObjectType decorator to UploadedInvestmentDocumentResponse and remove InputType from OmitType(UploadedDocumentResponse, ['documentType']), since I am creating an object that gets bind to a response field, not an input field !

opportunity-account.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[];

 

}