返回枚举 - 无法返回无效字段的null
我正在使用Apollo-Server-Lambda,Prisma Orm和GraphQl-Codegen。
我有一个查询(getBookById
),它返回book
。 book
包含一个名为bookstatus
的枚举。我希望能够在操场上的枚举中返回,但我会得到错误:
无法返回null for nullable field book.bookstatus。
bookstatus -typedef
enum BookStatus {
OPEN
DRAFT
CLOSED
}
book -typedef
type Book {
id: ID!
title: String!
bookStatus: BookStatus!
}
getBookBookbyId -typedef
type Query {
getBookById(getBookByIdInput: GetBookByIdInput): Book
}
I am using apollo-server-lambda, Prisma ORM and graphql-codegen.
I have a query (getBookById
) that returns a Book
. Book
contains an enum called BookStatus
. I want to be able to return in ENUM in the playground but I get the error:
Cannot return null for non-nullable field Book.bookStatus.
BookStatus - TypeDef
enum BookStatus {
OPEN
DRAFT
CLOSED
}
Book - TypeDef
type Book {
id: ID!
title: String!
bookStatus: BookStatus!
}
getBookById - TypeDef
type Query {
getBookById(getBookByIdInput: GetBookByIdInput): Book
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决:
问题是我正在使用Prisma作为ORM。
当我得到一本新书时,我正在编写代码:
问题是该书是使用此代码创建的:
Snake_case和Camelcase的组合创建了问题。
一旦一切都是骆驼,问题就解决了。
SOLVED:
The issue was that I was using Prisma as ORM.
When I was getting a new book, I was writing the code:
The issue is that the book was created using this code:
The mix of snake_case and camelCase created the issue.
Once everything was camelCase, the problem got solved.