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

查看:24
本文介绍了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 端点编写对象序列化程序的方式,该端点运行计算聚合计数所需的任何数据库查询.

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天全站免登陆