英文:
Sorting data in gql function from @apollo/client
问题
遇到了一个问题。该项目基于 NextJS 并使用 @apollo/client 库。我有一个查询如下:
export const GET_USERS = gql`
query User($uid: Int){
users(pagination: { limit: -1 }, sort: "guid desc, uid", filters: {uid: {eq: $uid}}){
data{
....
其中 guid 和 uid 是整数字段。
并且用户是按升序获取的,这是显而易见的。
我需要将排序改为降序,即从 guid 的最大值到最小值。
如何对 guid 字段进行降序排序?
尝试了不同的选项,如 sort: "guid desc, uid"、sort: "guid(desc), uid"、sort: "guid: desc, uid" 等等。尝试使用 sorts、sortBy、order、orderBy,但它们报错说未知参数。我尝试将一个对象放入 sort 中,但仍然报错,说需要字符串类型。
英文:
Faced a problem. The project is based on NextJS and uses the @apollo/client library. I have a query like:
export const GET_USERS = gql`
query User($uid: Int){
users(pagination: { limit: -1 }, sort: "guid, uid", filters: {uid: {eq: $uid}}){
data{
....
where guid and uid are integer fields.
And Users are obtained in ascending order, which is obvious.
I need the sort to be in descending order, i.e. from the largest value in guid to the smallest.
How to sort in descending order for the guid field?
Tried different options and sort: "guid desc, uid" sort: "guid(desc), uid" sort: "guid: desc, uid" and so on. Tried to use sorts, sortBy, order, orderBy, swears at them that unknown arguments. I tried to put an object in sort, swears, says that the string type was expected.
答案1
得分: 0
export const GET_USERS = gql`
query User($uid: Int){
users(pagination: { limit: -1 }, sort: { guid: -1, uid: 1 }, filters: {uid: {eq: $uid}}){
data{
....
英文:
export const GET_USERS = gql`
query User($uid: Int){
users(pagination: { limit: -1 }, sort: { guid: -1, uid: 1 }, filters: {uid: {eq: $uid}}){
data{
....
答案2
得分: 0
解决方案原来非常巧妙简单:sort: "guid: desc, uid"
选项是最接近的。正确的是:sort: "guid:desc, uid"
,即在***:***之后不需要空格。
英文:
The solution turned out to be ingeniously simple: The sort: "guid: desc, uid"
option was the closest. Correct: sort: "guid:desc, uid"
, i.e. after : no space needed...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论