我正在尝试创建一个 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/