gpt4 book ai didi

mongodb - (节点 :18560) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'typeFn' of undefined

转载 作者:行者123 更新时间:2023-12-05 00:56:49 24 4
gpt4 key购买 nike

当我尝试使用 @ResolveField() 装饰器解析字段( block )时出现此错误。

page.resolver.ts

import {
Resolver,
Query,
Mutation,
Args,
ResolveField,
Parent,
} from '@nestjs/graphql';
import { PageService } from './page.service';
import { PageType } from './type/page.type';
import { CreatePageInput } from './input/create-page.input';
import { BlockService } from '../block/block.service';
import { Page } from './page.interface';

@Resolver('Page')
export class PageResolver {
constructor(
private readonly pageService: PageService,
private readonly blockService: BlockService,
) {}

@Query(() => [PageType])
pages() {
return this.pageService.getAllPages();
}

@Query(() => [PageType])
async page(@Args('id') id: string) {
return this.pageService.getPage(id);
}

@Mutation(() => PageType)
createPage(@Args('createPageInput') createPageInput: CreatePageInput) {
return this.pageService.createPage(createPageInput);
}

@ResolveField()
blocks(@Parent() page: Page) {
return this.blockService.getManyBlocks(page.blockIds);
}
}

page.interface.ts

import { Document } from 'mongoose';

export interface Page extends Document {
readonly id: string;
readonly name: string;
readonly createdAt: Date;
readonly updatedAt: Date;
readonly createdBy: string;
readonly updatedBy: string;
readonly blockIds: string[];
}

最佳答案

@Resolver() 装饰器中使用函数 () => PageType 后解决了。

@Resolver(() => PageType)

关于mongodb - (节点 :18560) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'typeFn' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61578856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com