graphql可以返回汇总计数吗? [英] Can graphql return aggregate counts?

查看:76
本文介绍了graphql可以返回汇总计数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Graphql很棒,我已经开始在我的应用程序中使用它.我有一个显示摘要信息的页面,我需要graphql返回汇总计数吗?能做到吗?

Graphql is great and I've started using it in my app. I have a page that displays summary information and I need graphql to return aggregate counts? Can this be done?

推荐答案

您将定义一个新的GraphQL类型,该类型是一个包含列表和数字的对象.该数字将由解析器功能定义.

You would define a new GraphQL type that is an object that contains a list and a number. The number would be defined by a resolver function.

在GraphQL服务器上,您可以定义解析器功能,作为该功能的一部分,您将必须编写代码以执行获得总计计数所需的任何计算和查询.

On your GraphQL server you can define the resolver function and as part of that, you would have to write the code that performs whatever calculations and queries are necessary to get the aggregate counts.

这类似于您为REST API或运行任何需要数据库查询来计算总数的REST API或自定义REST API端点编写对象序列化器的方式.

This is similar to how you would write an object serializer for a REST API or a custom REST API endpoint that runs whatever database queries are needed to calculate the aggregate counts.

GraphQL的优势在于,它使前端有更大的能力来确定具体返回哪些数据.您在GraphQL中编写的某些内容将与您为REST API编写的内容相同.

GraphQL's strength is that it gives the frontend more power in determining what data specifically is returned. Some of what you write in GraphQL will be the same as what you would write for a REST API.

这篇关于graphql可以返回汇总计数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆