【发布时间】:2020-06-08 15:06:45
【问题描述】:
我的父模型(相机)包含子模型(传送带)的 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