Graphql:用户错误:应为可迭代的,但未为字段XXX找到可迭代的



这是电影模式:

type Book {
id: ID!
title: String
author: [Author] @belongsTo(relation: "author")
}

这就是我如何联系书籍和作者

public function author()
{
return $this->belongsTo('AppModelsAuthor', 'id', 'book_id');
}

这是作者的模式

type Author {
id: ID!
title: String!
book_id: Int!
}

这是我对图书的查询:

extend type Query {
bookCriteria(
orderBy: _ @orderBy
where: _ @whereConditions
): [Book!]! @paginate
}

这就是我的查询方式:

{
bookCriteria
(
first: 1, page: 1
)
{
data
{
id
uuid
author
{
id
title
}
}
}
}

最后,这是我得到的错误消息:

"用户错误:应为可迭代的,但没有为字段Book.author找到可迭代的

如果我使用hasMany而不是belongsTo,效果很好。

请告诉我这里出了什么问题?

您的类型应该是

type Book {
id: ID!
title: String
author: Author @belongsTo(relation: "author")
}

最新更新