(节点:18560)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“typeFn”

Posted

技术标签:

【中文标题】(节点:18560)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“typeFn”【英文标题】:(node:18560) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'typeFn' of undefined 【发布时间】:2020-08-18 02:09:33 【问题描述】:

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

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[];

【问题讨论】:

我很确定如果您使用的是@ResolveField(),您需要在@Resolver() 装饰器中使用一个函数,例如@Resolver(() => Page) 谢谢,使用@Resolver(() => PageType)后解决了 【参考方案1】:

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

@Resolver(() => PageType)

【讨论】:

以上是关于(节点:18560)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“typeFn”的主要内容,如果未能解决你的问题,请参考以下文章

ceph故障:too many PGs per OSD

将 NodeJS Docker 容器连接到 MySQL Docker 容器 - docker-compose 3

CEPH -S集群报错TOO MANY PGS PER OSD

Delphi TreeView 选择父节点,选择所有子节点

js DOM知识总结

给出一个二叉树的节点,返回该节点的前驱节点