从过滤结果集中的hotchocaly差异值
我有一张SQL桌子看起来像:
ID | 产品 | 用户 | 状态 | 创建日期 |
---|---|---|---|---|
1 | 奶酪 | John | New | 2022-02-07 |
2 | 牛奶 | Steve | pergend redend redend redend | 2022-06-12 |
3 | Juice | Steve Steve | New | 2022-06-10 |
4 | Beer | Lloyd | 完成 | 2021-12-01 |
5 | 苹果 | 路易斯 | 完成 | 2022-05-10 |
6 | 橙子 | 约翰 | 待定 | 2022-05-10 |
7 | 胡萝卜 | 约翰· | 2022-06-23 | 8 |
Cookies | Fred | 取消 | 了 | 2021-11-07 |
9 | Jelly | Luis | 纽 | 2021-05-30 |
在网页上 在网页上,I AM在页面中显示此表,3个项目:
第1页:
ID | 产品 | 用户 | 状态 | 创建日期 |
---|---|---|---|---|
1 | 奶酪 | John | New | 2022-02-07 |
2 | 牛奶 | Steve | perdeve pernew | 2022-06-12 |
3 | Juice | Steve Steve Steve | New | 2022-06-10 |
Page 2:
ID | 产品 | 用户 | 状态 | 创建日期 |
---|---|---|---|---|
4 | 啤酒 | 劳埃德 | 完成 | 2021-12-01 |
5 | Apples | Luis | 完成 | 2022-05-10 |
6 | ORANGES | JOHN JOHN | pENDENG | 2022-05-10 |
等。
现在,使用ODATA查询,我可以使用此类疑问过滤此表:
/odata/products?$filter=Status eq 'New'
或
/odata/products?$filter=CreatedDate eq '2022-05-10'
I i我正在动态创建这样的过滤器。
现在,对于已过滤或未经过滤的结果,我想检索例如用户或状态的不同列表:
- 要获取状态“ new”的用户列表,我正在发送此odata查询:
/odata/products。 ?$ apply = filter(状态eq'new')/groupby((用户))
- 要获取所选用户的不同状态列表,我正在发送此odata查询:
/odata/products?$ $ apply = filter(用户eq'steve')/groupby((状态))
我如何使用GraphQl实现类似的东西,尤其是使用Hotchocaly?
接收过滤结果很简单 - 只需通过过滤和分页创建查询即可。 但是,从过滤数据集中检索不同的值呢?这样的查询不得使用分页 - 我们应该从所有页面中获得不同的值,而不仅仅是第2页。
I have a sql table looking like this:
ID | Product | User | Status | CreatedDate |
---|---|---|---|---|
1 | Cheese | John | New | 2022-02-07 |
2 | Milk | Steve | Pending | 2022-06-12 |
3 | Juice | Steve | New | 2022-06-10 |
4 | Beer | Lloyd | Finished | 2021-12-01 |
5 | Apples | Luis | Finished | 2022-05-10 |
6 | Oranges | John | Pending | 2022-05-10 |
7 | Carrots | John | New | 2022-06-23 |
8 | Cookies | Fred | Canceled | 2021-11-07 |
9 | Jelly | Luis | Pending | 2021-05-30 |
On web page, I am showing this table in pages, by 3 item:
Page 1:
ID | Product | User | Status | CreatedDate |
---|---|---|---|---|
1 | Cheese | John | New | 2022-02-07 |
2 | Milk | Steve | Pending | 2022-06-12 |
3 | Juice | Steve | New | 2022-06-10 |
Page 2:
ID | Product | User | Status | CreatedDate |
---|---|---|---|---|
4 | Beer | Lloyd | Finished | 2021-12-01 |
5 | Apples | Luis | Finished | 2022-05-10 |
6 | Oranges | John | Pending | 2022-05-10 |
etc.
Now, using odata query, I can filter this table using such query:
/odata/products?$filter=Status eq 'New'
or
/odata/products?$filter=CreatedDate eq '2022-05-10'
I am creating such filters dynamically.
Now, for filtered or unfiltered results I would like to retrieve distinct list of, for example, Users or Statuses:
- to get distinct list of Users for status 'New' I am sending for example this odata query:
/odata/products?$apply=filter(Status eq 'New')/groupby((User))
- to get distinct list of Statuses for selected User I am sending for example this odata query:
/odata/products?$apply=filter(User eq 'Steve')/groupby((Status))
How can I achieve something similar using graphql, especially with HotChocolate?
Receiving filtered results are simple - just create a query with filtering and paging.
But what about retrieving distinct values from filtered dataset? Such a query must not use paging - we should get distinct values from all pages, not just from page 2 for instance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论