无法将自定义结果从解析器传递到 Graphql

Cannot pass custom result from resolver to Graphql

我正在尝试使用带有属性的 sequelize 获取数据并将其传递给 graphql。 结果在控制台中很好,但 graphql 查询为属性字段返回 null。

我的解析器

    getUnpayedLessons: async (_, args, { models }) => {
  const { Attendance, Student } = models;
  return await Attendance.findAll({
    include: {
      model: Student,
    },
    where: {
      fk_lessonsSerieId: { [Op.is]: null },
    },
    attributes: ["id", [sequelize.fn("count", sequelize.col("absenceFlag")), "unpayedLessons"]],
    group: ["student.id"],
  });
},

查询

getUnpayedLessons {
  id
  unpayedLessons
  student {
    id
    firstName
    lastName
  }
}

架构

type UnpayedLessons {
  id: Int
  unpayedLessons: Int
  student: Student
  }

extend type Query {
  getUnpayedLessons: [UnpayedLessons]
  }

这是解析器的 console.log 当我 运行 查询

    [
   attendance {
    dataValues: { id: 2, unpayedLessons: 8, student: [student] },
    _previousDataValues: { id: 2, unpayedLessons: 8, student: [student] },
    _changed: Set {},
    _options: {
      isNewRecord: false,
     _schema: null,
     _schemaDelimiter: '',
      include: [Array],
      includeNames: [Array],
      includeMap: [Object],
      includeValidated: true,
      attributes: [Array],
      raw: true
     },
]

来自 graphql

    {
  "data": {
    "getUnpayedLessons": [
      {
        "id": 2,
        "unpayedLessons": null,
        "student": {
          "id": 2,
          "__typename": "Student"
        },
        "__typename": "UnpayedLessons"
      },
     ]
    }
   }

知道如何将 unpayedLessons 传递给 graphql 吗?

要调试它,您需要检查从数据库返回的内容,形状:

const values = await Attendance.findAll({...
console.log( values );
// adapt structure to match query requirements
// finally return
return values;