我在编写@Query Decorator for getAccountAssets Resolver方法时遇到以下错误:

当作为表达式调用时,无法解析方法decorator 的签名. 类型'TypedProperty Description(userTokenPayload:UserTokenPayload,accountType:AccountType)= Promise'的参数不能分配给类型'number'的参数.ts(1241)<>> 没有与此调用匹配的重载. 过载1/3,"……管道:(PipeTransform any,any<输入PipeTransform any,any)[]):PartnerDecorator ',给出了以下错误.>|<<>> 类型'()= typeof AllAccountAssetsResponse'的参数不能分配给类型'PipeTransform any,any'的参数>键入PipeTransform any,any '.<>|<<>> 重载2,共3个,'(属性:字符串,...管道:(PipeTransform any,any<输入PipeTransform any,any)[]):PartnerDecorator ',给出了以下错误.>|<<>> 类型'()= typeof AllAccountAssetsResponse'的参数不能分配给类型'string'的参数.ts(2769)>

import { CustomerService } from '@app/customers/customers.service';
import { CurrentUserTokenPayload } from '@auth/decorators';
import { UserTokenPayload } from '@auth/dto/auth.interfaces';
import { GqlAuthGuard } from '@auth/guards';
import { Query, UseGuards } from '@nestjs/common';
import {
  Args, Mutation, Resolver,
} from '@nestjs/graphql';

import { AccountType } from './dto/accounts.interfaces';
import {
  UpdateThirdPartyFundingInfoInput,
} from './dto/common-account.input';
import {
  AccountResponse, AllAccountAssetsResponse,
} from './dto/common-account.response';
import { OpportunityAccountsService } from './opportunity-accounts.service';
import { StandardAccountsService } from './standard-accounts.service';

@Resolver(() => AccountResponse)
export class CommonAccountResolver {
  constructor(
    private readonly standardAccountsService: StandardAccountsService,
    private readonly opportunityAccountsService: OpportunityAccountsService,
    private readonly customerService: CustomerService,
  ) { }

  async getAccountServiceByType(params: {
    accountType: AccountType; userId: string;
  }) {
    const { accountType, userId } = params;
    const {
      customerId,
      resourceRelationships: { standardAccountId, opportunityAccountId },
    } = await this.customerService.validateCustomerRelationship({ userId });
    return {
      [AccountType.OPPORTUNITY]: {
        accountService: this.opportunityAccountsService,
        accountId: opportunityAccountId,
        customerId,
      },
      [AccountType.STANDARD]: {
        accountService: this.standardAccountsService,
        accountId: standardAccountId,
        customerId,
      },
    }[accountType];
  }



  @UseGuards(GqlAuthGuard)
  @Query(() => AllAccountAssetsResponse) // error is happening here
  async getAccountAssets(
    @CurrentUserTokenPayload() userTokenPayload: UserTokenPayload,
    @Args('accountType', { type: () => AccountType }) accountType: AccountType,
  ) : Promise<AllAccountAssetsResponse> {
    const { accountId, accountService } = await this.getAccountServiceByType({
      accountType, userId: userTokenPayload.sub,
    });

    const accountAssetDetails = await accountService.getAccountAssets({
      accountId,
    });
    return accountAssetDetails;
  }
}

response.ts:-

import {
  createUnionType, Field, ObjectType,
  registerEnumType,
} from '@nestjs/graphql';
import { Type } from 'class-transformer';
import { IsArray } from 'class-validator';

import { AssetStatus, ProductType } from '@/generated-cbms-api-client';

import { AccountType } from './accounts.interfaces';
import { OpportunityAccount } from './opportunity-account.response';
import { StandardAccount } from './standard-account.response';

registerEnumType(AssetStatus, { name: 'AssetStatus' });
registerEnumType(ProductType, { name: 'ProductType' });

export const AccountDetails = createUnionType({
  name: 'AccountDetails',
  types: () => [OpportunityAccount, StandardAccount] as const,
  resolveType:
    (accountDetails) => {
      if ('accountPurpose' in accountDetails) {
        return StandardAccount;
      }
      return OpportunityAccount;
    },
});

@ObjectType()
export class AccountResponse {
  @Field(() => AccountType)
  accountType: AccountType;

  @Field(() => AccountDetails)
  accountDetails: OpportunityAccount | StandardAccount;
}

@ObjectType()
export class AccountAssetResponse {
  @Field(() => AssetStatus)
  status: AssetStatus;

  @Field(() => ProductType)
  productType: ProductType;

  @Field(() => String)
  createdAt?: string;

  @Field(() => String)
  updatedAt?: string;

  @Field(() => String)
  assetTypeId: string;

  @Field(() => String)
  productId: string;

  @Field(() => String)
  customerId: string;

  @Field(() => String)
  currentBalance: string;

  @Field(() => String)
  availableBalance: string;

  @Field(() => String)
  parentAccountId: string;
}

@ObjectType()
export class AllAccountAssetsResponse {
  @IsArray()
  @Type(() => AccountAssetResponse)
  @Field(() => [AccountAssetResponse], { description: 'Expected investment support info' })
  accountAssets: AccountAssetResponse[];

  @Field(() => String)
  nextCursor: string;

  @Field(() => Boolean)
  hasMore: boolean;

  @Field(() => Number)
  totalCount: number;
}

我不知道我错过了什么.答案accountService.getAccountAssets也符合Promise<AllAccountAssetsResponse>.

推荐答案

你在导入Query时犯了一个错误:

import { Query, UseGuards } from '@nestjs/common'

你需要从@nestjs/graphql:

import { Query } from '@nestjs/graphql';

Here是来自nestjs的样本库的一个文件,它导入了Query.

Javascript相关问答推荐

JavaScript文本区域阻止KeyDown/KeyUp事件本身上的Alt GR +键组合

*ngFor和@代表输入decorator 和选角闭合

成帧器运动中的运动组件为何以收件箱开始?

使用useup时,React-Redux无法找到Redux上下文值

Klaro与Angular的集成

按钮未放置在html dis位置

我开始使用/url?q=使用Cheerio

扫描qr code后出错whatter—web.js

如何修复我的js构建表每当我添加一个额外的列作为它的第一列?

colored颜色 检测JS,平均图像 colored颜色 检测JS

当id匹配时对属性值求和并使用JavaScript返回结果

JS:XML insertBefore插入元素

如何在Angular拖放组件中同步数组?

Reaction Redux&Quot;在派单错误中检测到状态Mutations

我想将Sitecore搜索面过滤器从多个转换为单个

构建器模式与参数对象输入

不协调嵌入图片

每隔一行文本段落进行镜像(Boustrophedon)

已在EventListener中更新/更改异步的React.js状态对象,但不会导致组件重新呈现

如何使用Angular JS双击按钮