【问题标题】:Expected Iterable but did not find one for field预期可迭代,但没有找到一个字段
【发布时间】:2019-08-01 03:10:13
【问题描述】:

使用 GraphQL 和 SQLite,这是我的查询:

{
book {
  id
  authors {
    name
  }
 }
}

种类:

  type Book {
    id: ID!
    title: String
    actors: [Author!]!
  }
  type Author {
    id: ID!
    name: String
  }

这是我的决心:

const resolvers = {
  Query: {
        book: async (_, __, { db }) => {
      return await db.all('SELECT * FROM books');
    },
  }
};

错误是:

"message": "预期为 Iterable,但没有为字段找到一个 Book.authors.",

【问题讨论】:

    标签: javascript sqlite graphql


    【解决方案1】:

    在您的查询解析器中,您只是从您选择的'SELECT * FROM books' 中解析books

    如果您希望能够查询booksauthors,并且只有一个解析器,则必须返回两个对象,即您必须在解析器book 中构建并返回完整对象。

    【讨论】:

      猜你喜欢
      • 2020-07-04
      • 2021-09-14
      • 2021-01-20
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多