gpt4 book ai didi

node.js - graphql.js : field is null even though resolver is returning value for sequilize query

转载 作者:行者123 更新时间:2023-12-03 22:28:03 26 4
gpt4 key购买 nike

我有以下 graphql 架构,我正在尝试执行 businessUser 查询

type Query {
businessUser(id: String!): BusinessUser
}

type BusinessUser {
id: ID!,
firstName: String,
lastName: String,
email: String,
posts: [BusinessPostFormat]
}

type BusinessPostFormat {
postId: Int,
user: String,
isActive: Boolean,
postText: String
}

在我的解析器中,我将 Post 表与 businessPost 表连接起来以检索“isActive”列。当我打印出 Sequilize 返回的内容时,我看到我返回的正是应该映射到 BusinessPostFormat 类型的数据对象:
post {
dataValues:
{ postId: '188',
postText: 'blah blah blah',
user: 'userName',
isActive: false },

但是,当我在 graphiql 中执行查询时,isActive 字段返回为空。如果我能看到解析器返回的正是 BusinessPostFormat 类型所期望的,我不明白为什么会发生这种情况?

解析器功能如下:
const resolvers = {
Query: {
businessUser(_, args) {
return BusinessUser.findById(args.id);
}
},
BusinessUser: {
posts(businessUser) {
return businessUser.getPosts({
attributes: {
include: [[Sequelize.literal('business_posts.is_active'), 'isActive']],
exclude: ['business_user_id']
},
include: [{ model: BusinessPost, attributes: ['is_active'] }]
})
},
}

最佳答案

也许您忽略了 Sequelize 使用实例 http://docs.sequelizejs.com/manual/tutorial/instances.html 的事实,也许这就是本例中缺少的事实。
像这样试试。

return Entries.findAll().then(entries => {
return entries.map(e => e.get({ plain: true }));
})

关于node.js - graphql.js : field is null even though resolver is returning value for sequilize query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48968872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com