gpt4 book ai didi

node.js - 无法从 TypeScript 反射系统推断 GraphQL 类型

转载 作者:行者123 更新时间:2023-12-04 12:10:04 25 4
gpt4 key购买 nike

我正在尝试创建一个 Alert 类,如下所示:

@ObjectType()
export class Alert {
@Field()
status: 'error' | 'success' | 'warning' | 'info' | undefined

@Field(() => [String])
messages: string[];
}
但是,它给了我以下错误消息:

Error: Unable to infer GraphQL type from TypeScript reflection system.You need to provide explicit type for 'status' of 'Alert' class.

最佳答案

'error' | 'success' | 'warning' | 'info' | undefined 创建类型并将其添加到字段定义中:@Field(() => StatusType)它基本上是在提示它无法推断该字段的类型,因为它不是原始类型,每当字段是对象或其他用户定义的类型时,您都需要提供类型信息,如我所描述的

关于node.js - 无法从 TypeScript 反射系统推断 GraphQL 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63532777/

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