Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Order by multiple fields #62

Closed
marktani opened this issue Jan 10, 2017 · 44 comments
Closed

Order by multiple fields #62

marktani opened this issue Jan 10, 2017 · 44 comments

Comments

@marktani
Copy link
Contributor

{
  # order ascending by name first, then descending by birthday
  allUsers(orderBy: [name_ASC, birthday_DESC]) {
    id
  }
}
@dohomi
Copy link

dohomi commented Feb 14, 2017

very important.. would love to see this feature out of the backlog :)

@lucasfeliciano
Copy link

Yes! :)

@njreid
Copy link

njreid commented Jun 24, 2017

Yes please!

@kbrandwijk
Copy link
Contributor

Would be half a feature if it was limited to top level fields. I think the orderBy parameter Type should mirror the query Type, so all fields down the hierarchy are available for orderBy.

@jjwp
Copy link

jjwp commented Nov 30, 2017

@kbrandwijk half a feature is better than not having it at all. Would love to see this live, we currently have a use case for ordering by a category first, then a date field.

@renecvt
Copy link

renecvt commented Mar 2, 2018

Any news on this?

@LucaGabi
Copy link

LucaGabi commented Apr 3, 2018

Hi .. I also have an idea (just as an idea to be improved if considered..):


query{
  films{
    title[='st%'*='at%']
    +year[=1998*=2011..2013*>2016]
    +auth
    +cinemas|skip,take|{
        city|asc|[='bu%']
        +d=dist(#c,l)|desc|[<=700]}
  }
}



Where operator:  
* is 'or'  
+ is 'and'   
.. is 'between'  
... is 'open right range [..)'  
.... is 'open right range (..]'   
field[op value ...] is where field op value  i.e. age[>22]  
d is 'computed field' 
#c is a parameter  
field|skip,take| is paging on collection  
field|desc| is order desc  
[=val,...] equal sign can be implicit and omitted

@phunkren
Copy link

phunkren commented Apr 9, 2018

Can anyone give a status update on this please?

@PascalSenn
Copy link

PascalSenn commented Apr 18, 2018

I built a filter abstraction for graphql-dotnet, which is similar to prisma.
I did solve that issue with passing all filterable items to orderBy as own properties:

query{
  servers(
  orderBy: {
    active: DESC
    assetNumber: ASC
  }
  ) {
    id
    active
    assetNumber
  }
}

You can even specify the order of orderBy statements. The example above is first ordered by active and then by assetNumber. The following would be first ordered by assetNumber and then by active

...
  orderBy: {
    assetNumber: ASC
    active: DESC
  } 
...

That would also be a solution for #95

query{
  servers(
  orderBy: {
    active: DESC
    assetNumber: ASC
    customer: {
        name:ASC 
   }
  }
  ) {
    id
    active
    assetNumber
    customer {
         name
    }
  }
}

That probably would end up in breaking changes though.

@Yogu
Copy link

Yogu commented Apr 18, 2018

How do you specify the order (sequence) of the order clauses? Does graphql.net preserve the order of input fields? But even if it does, the client may have problems preserving the order of properties in a variable value. Otherwise, I'd go with an array of enums (the enums being prisma's current enum) - that's how we do it in cruddl.

@PascalSenn
Copy link

PascalSenn commented Apr 18, 2018

@Yogu it doesn't. Just tried.

@PascalSenn
Copy link

It does preserve the order. The problem was that I didn't handle OrderBy and ThenBy properly.
For my case it does work.

Json serializers should preserve the order.
At least JS (Chrome 65) does:

var serializationObjectBefore = {
	orderBy: {
        customer: "Test",
        active: "Test"
    }
}
var first = JSON.stringify(serializationObjectBefore) 
var serializationObjectAfter = JSON.parse(first) 
var second = JSON.stringify(serializationObjectAfter) 
var serializationObjectBefore =  JSON.parse(first) 
second
"{"orderBy":{"customer":"Test","active":"Test"}}"
first
"{"orderBy":{"customer":"Test","active":"Test"}}"

But still.
I'd rather use nested objects if you want to ensure compatibility:

orderBy: {
      assetNumber: {
            position: 1,
            direction: DESC
     }
}

@PascalSenn
Copy link

@Yogu

"GraphQL Objects represent a list of named fields, each of which yield a value of a specific type. Object values should be serialized as ordered maps, where the queried field names (or aliases) are the keys and the result of evaluating the field is the value, ordered by the order in which they appear in the query."

http://facebook.github.io/graphql/October2016/#sec-Objects

@dohomi
Copy link

dohomi commented Nov 15, 2018

@sorenbs thanks for the clarification I already had the feeling that there is nothing happen any longer in the graph.cool world. Sad for me I thought that it was an amazing idea and I have many production apps online.

@FluorescentHallucinogen

@sorenbs

First of all - I'm sorry that we published a roadmap, and then failed to deliver on it in a timely manner and furthermore failed to communicate our lack of progress. We will do better in the future.

When the public roadmap will be eventually published (see #2142)?

@stale
Copy link

stale bot commented Jan 8, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status/stale Marked as state by the GitHub stalebot label Jan 8, 2019
@zhiwenjunjin
Copy link

zhiwenjunjin commented Jan 17, 2019

any update on this, nya?

@stale stale bot removed the status/stale Marked as state by the GitHub stalebot label Jan 17, 2019
@jvlobo
Copy link

jvlobo commented Jan 19, 2019

any plans on implementing this feature? it seems like a very important one to have...

@jwld
Copy link

jwld commented Mar 4, 2019

Would love to see this added 🙏

@oreillyross
Copy link
Contributor

Yes me too, would love to have this feature built-in

@kumarabhirup
Copy link

I need this feature!

@MikeAliG
Copy link

+1

@bkstorm
Copy link

bkstorm commented May 20, 2019

this issue was removed from ROADMAP.md 5 days ago :(

@iwasingh
Copy link

iwasingh commented May 27, 2019

Would love to see orderBy by multiple fields and inner relations ordering

Any updates?

@mahapo
Copy link

mahapo commented Jul 1, 2019

+1

@esausilva
Copy link

This is a must have feature. I hope Prisma 2 can bring it to life 🙏

@tafelito
Copy link

tafelito commented Nov 13, 2019

@sorenbs none of you large customers had to implement something like this? It seems to be a pretty common use case

@Jaikant
Copy link

Jaikant commented Dec 12, 2019

This is a much needed feature, even for hobby project!

@anaibol
Copy link

anaibol commented Mar 26, 2020

I switched to AWS AppSync

@charleslouis
Copy link

Hi,
This is indeed so much needed 🙏

@phryneas
Copy link

@charleslouis This will not be coming. Prisma 1 is dead.

@charleslouis
Copy link

@phryneas alright. Thanks for letting me know.

@beautimode
Copy link

+1

1 similar comment
@deanshelton913
Copy link

+1

@janpio janpio closed this as completed Sep 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests