prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

Order by multiple fields

Open marktani opened this issue 8 years ago • 44 comments

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

marktani avatar Jan 10 '17 15:01 marktani

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

dohomi avatar Feb 14 '17 01:02 dohomi

Yes! :)

lucasfeliciano avatar Jun 15 '17 13:06 lucasfeliciano

Yes please!

njreid avatar Jun 24 '17 20:06 njreid

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.

kbrandwijk avatar Jun 24 '17 21:06 kbrandwijk

@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.

jjwp avatar Nov 30 '17 11:11 jjwp

Any news on this?

renecvt avatar Mar 02 '18 00:03 renecvt

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|[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

LucaGabi avatar Apr 03 '18 07:04 LucaGabi

Can anyone give a status update on this please?

phunkren avatar Apr 09 '18 15:04 phunkren

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.

PascalSenn avatar Apr 18 '18 06:04 PascalSenn

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.

Yogu avatar Apr 18 '18 07:04 Yogu

@Yogu ~it doesn't. Just tried.~

PascalSenn avatar Apr 18 '18 07:04 PascalSenn

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 avatar Apr 18 '18 08:04 PascalSenn

@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

PascalSenn avatar Apr 25 '18 16:04 PascalSenn

This ticket was originally for the graphcool framework. I do wonder if there is any progress for it or will it only be target in prisma?

dohomi avatar May 10 '18 12:05 dohomi

It is more import for productive development , please

yuguangmao avatar Jun 03 '18 10:06 yuguangmao

I think the nested object approach (or any other that solves the below scenaro) is better for solving #95 too, because it'd be possible to use something like

orderBy: {
    customer: {
        name: {
            position: 1
            direction: ASC
        }
        age: {
            position: 3
            direction: DESC
        }
    }
    active: {
            position: 2
            direction: DESC
    }
}

which couldn't be done using the positional solution (the customer key can't be used twice).

orderBy: {
    customer: { name: ASC }
    active: DESC
    // it can't be used like this
    customer: { age: DESC }
}

Anyway, this issue as well as #95 are very important and an official update from the prisma team would be awesome.

renato avatar Jun 29 '18 20:06 renato

I really need order by multiple fields for my project.

@marktani @mavilein @nikolasburk @timsuchanek @do4gr @dpetrick @schickling @sorenbs Any info when this feature will be finally implemented?

FluorescentHallucinogen avatar Jul 14 '18 12:07 FluorescentHallucinogen

Any news about this ? Since Q3 is over ;)

Simmetopia avatar Nov 07 '18 12:11 Simmetopia

When did Primsa become closed source? Instead of this entitlement attitude, why aren't some of you getting your hands dirty and implementing it?

You all claim its important to your business.

If you can't implement it then put your money where your mouth is and pay the active developers to get this done.

But stop the whining, that isn't helpful at all.

-- a grumpy bystander

baerrach avatar Nov 07 '18 22:11 baerrach

I started a bounty: https://www.bountysource.com/issues/40808836-order-by-multiple-fields

I will get my company to fund it with 500$ or more tomorrow.

If we can get people to increase the bounty I will be more than happy to distribute the funds to the developers who help move the ball on this.

harrisrobin avatar Nov 07 '18 23:11 harrisrobin

@baerrach

image

From: https://blog.codinghorror.com/dont-like-it-code-it-yourself/

developer239 avatar Nov 07 '18 23:11 developer239

@developer239 Cheers! I knew I had read that article, but its more fun to craft a curmudgeon reply than send in a link - that these young whipper snappers won't bother reading anyway!

@harrisrobin Thanks for putting up a bounty. Great idea.

baerrach avatar Nov 07 '18 23:11 baerrach

Thanks a lot everyone for the passionate discussion here! There are several issues that I need to address individually.

Roadmap

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. Prisma is a complex project, and we have been overwhelmed by the structural work required to prepare to support multiple database connectors. With the upcoming release of the MongoDB connector we will soon see the fruits of this work.

At the same time some of our larger customers were experiencing slower performance than expected for certain query patterns. After analysing the situation, we decided to dedicate a substantial part of our engineering team to improve general performance for Prisma. We wrote about the result of this work here and I am happy that all users can now benefit from these improvements.

Bottom line is that we have to balance tradeoffs when we decide what features or improvements to work on. I appreciate your continued support as we keep improving Prisma one small feature at a time 🙏

We are currently hiring for several positions to help us accelerate feature development. If you know a good backend/systems engineer, the most impactful way to help us ship features faster is to convince him or her to apply for a job at Prisma :-)

Open source contributions

While I truly appreciate the sentiment by @baerrach to dig in and contribute, I also acknowledge that Prisma is a very complex project to contribute to. It certainly is possible for members of the community to contribute to Prisma, but we have found the overhead of getting to know the entire system before being able to contribute is so high that it is difficult to justify as a regular Prisma user. We very much do welcome contributions, but I think the only sustainable solution is to increase our engineering team.

Thank you very much @harrisrobin for offering a bounty on this feature. I'm sure that will help encourage the community. It certainly got some of our internal developers excited :-D

Graphcool

@dohomi - We are no longer doing active feature development on Graphcool. We are constantly working to make Prisma easier to use and hope to eventually be able to approach the seamless experience of using Graphcool. The recent launch of graphqlgen is the latest step in that direction.

sorenbs avatar Nov 14 '18 13:11 sorenbs

@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.

dohomi avatar Nov 15 '18 01:11 dohomi

@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)?

FluorescentHallucinogen avatar Nov 15 '18 18:11 FluorescentHallucinogen

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[bot] avatar Jan 08 '19 16:01 stale[bot]

any update on this, nya?

zhiwenjunjin avatar Jan 17 '19 04:01 zhiwenjunjin

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

jvlobo avatar Jan 19 '19 23:01 jvlobo

Would love to see this added 🙏

jwld avatar Mar 04 '19 22:03 jwld

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

oreillyross avatar Mar 20 '19 16:03 oreillyross