NestJS:使用ResolveProperty时出现问题。得到了“ UnhandledPromiseRejectionWarning:TypeError:”

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

我的父模型(相机)包含子ID(传送带),如下所示:

@ObjectType('camera')

export class CameraModel {
  @Field(() => ID)
  _id: String;

  @Field()
  name: String;

  @Field(() => ConveyorModel)
  conveyor: ConveyorModel;
}

因此,为了获得“传送带”的详细信息,我需要在camera.resolver.ts中使用@ResolveProperty装饰器(注意:仅显示相关方法)

import { CameraModel } from './models/camera.model';
import { ConveyorService } from "../conveyor/conveyor.service";
import { ConveyorModel } from "../conveyor/models/conveyor.model";

@Injectable()
export class CameraResolver {
  constructor(    
    private conveyorService: ConveyorService, 
    private cameraService: CameraService,
    ) {}

  @ResolveProperty('conveyor', type => ConveyorModel)  
  async getConveryor(@Parent() CameraModel) {
    const { cid } = CameraModel;
    return this.conveyorService.findOne(cid);     
  }
}

运行服务器后出现以下错误。主要来自graphql模式生成器。

(node:30636) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getObjectType' of undefined

...

(node:30636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:30636) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

但是,如果我注释掉@ResolveProperty块,一切都会很好。但是我不能只获取传送带的详细信息(仅获取ID)。

我在这里想念什么?

graphql code-first nestjs
1个回答
0
投票

基于我在https://github.com/nestjs/graphql/issues/158上发现的相关问题>

已修复。

不要使用@Resolver('YourModel')的字符串基础修饰符。只需使用@Resolver(of => YourModel);

这部分的NestJS文件确实不足。

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