Graphql: User Error: expected iterable, but did not find one for field XXX

Graphql: User Error: expected iterable, but did not find one for field XXX

这是电影架构:

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

这就是我将书和作者联系起来的方式

public function author()
{
    return $this->belongsTo('App\Models\Author', '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")
}