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

标签 node.js typescript graphql

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

相关文章:

sql - Node.js 和 SQL Server Sequelize 连接表

html - 在 Node.js 和 Html 之间传递数据

node.js - 从模块中使用 socket.io

javascript - Angular2 - 路由器不选择路由/主路径

visual-studio - VSCode : how to scroll through IntelliSense overload signature suggestions

mysql - 如何并行运行sql查询

typescript - 使用 VS2017 将 typescript 编译、打包并缩小为 JavaScript

graphql - 无法在 AEM 中使用 GraphQL

使用代码生成的 graphql 代码时出现 Typescript 错误 "Property ' 0' does not exist on type X"

javascript - 如何在 header 中正确提供身份验证 token ,以便 graphql 不会重定向到登录页面?