【发布时间】:2020-10-28 01:06:37
【问题描述】:
我正在尝试使用 GraphQl 来计算表中的条目数,我遇到了解析器问题,我不知所措。当我记录 rows[0] 时,计数有效,但在使用 graphiql 时我无法访问它,条目为空。
我的类型:
const TableCount = new graphql.GraphQLObjectType({
name: "Count",
fields: {
entries: { type: graphql.GraphQLInt }
}
});
我的查询:
var queryType = new graphql.GraphQLObjectType({
name: 'Query',
fields: {
tableCount:{
type: TableCount,
resolve: (source, args)=>{
return new Promise((resolve, reject)=>{
database.all("Select COUNT(*) from projects", function(err, rows){
if(err){
reject(err)
}resolve(rows[0])
console.log(rows[0])
})
})
}
},
【问题讨论】:
-
tableCount 正在返回 [{"Count()": 17}] 的对象。访问“Count()”属性更正了问题
标签: angular sqlite graphql apollo