【问题标题】:GraphQl Count Aggregate entriesGraphQl 计数聚合条目
【发布时间】: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


【解决方案1】:

好的,对于任何可能在同一教程中犯同样错误的人,我意识到我的错误。
决心应该是这样的

resolve({
   entries: rows[0]["COUNT(*)"]
})

【讨论】:

  • 它是 SQL 查询吗?
猜你喜欢
  • 2016-03-23
  • 2021-07-30
  • 2018-10-26
  • 1970-01-01
  • 2022-11-04
  • 2018-08-25
  • 2016-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多