Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: deep sorting #145

Open
Andy2003 opened this issue Mar 4, 2021 · 9 comments
Open

Proposal: deep sorting #145

Andy2003 opened this issue Mar 4, 2021 · 9 comments
Labels

Comments

@Andy2003
Copy link
Contributor

Andy2003 commented Mar 4, 2021

As explained in neo4j-graphql/neo4j-graphql-java#64 I would suggest to change the way sorting is defined.

Given the Schema:

type Movie {
  title: String
  publishedBy: Publisher @relation(name: "PUBLISHED_BY", direction: OUT)
}

type Publisher {
  name: ID!
}

The augmentation would be:

type Query {
  movie(sort: [_MovieSorting!]): [Movie!]!
}
enum SortDirection{
  asc,
  desc,
}

input _MovieSorting {
  title: SortDirection
  publishedBy: [_PublisherSorting!]
}

input _PublisherSorting {
  name: SortDirection
}

So a user can get all movies ordered by Publisher.name and title by calling

query {
  movie(sort: [{publishedBy: [{name: desc}]}, {title: asc}]) {
    title
  }
}

which results in this query

MATCH (m:Movie)
WITH m
  ORDER BY head([(m)-[:PUBLISHED_BY]->(p:Publisher) | p.name]) DESC, m.name ASC
RETURN m{.title}

This sorting should be possible for all 1..1 relations.

@darrellwarde
Copy link
Contributor

This is great @Andy2003, thanks for the proposal. Today is the deadline for us to propose new pieces of work for the next development phase, so we sadly haven't got time to fully elaborate this in time.

However, I have proposed refactoring from our current enum sort types to object sort types better aligned with the Java library, which will put us in a much better position to implement this feature in the future, without making any breaking changes.

@Andy2003
Copy link
Contributor Author

Andy2003 commented Mar 5, 2021

@darrellwarde I'm currently scanning the API to find the work to do, to align the java-version. I think, now is a good point in time to optimize the API. Sad to hear that the Deadline is so close.

@darrellwarde
Copy link
Contributor

For sure, for me it's very much about getting as many breaking changes as possible out of the way before we release version 1.0.0. For clean additions of functionality, not so much of a problem, but this change would require underlying changes to enable it. At the very least, we can get the underlying change requirements out of the way, and then we can cleanly add it later without breaking any schemas out in the wild. 🙂

Yes, there is a bit of a deadline, but we often have time to squeeze other bits of work in, so please don't slow down on raising these kinds of issues! 🔥

@darrellwarde darrellwarde transferred this issue from another repository Apr 8, 2021
@darrellwarde darrellwarde added inbox feature request New feature or request labels May 7, 2021
@rcbevans
Copy link
Contributor

rcbevans commented Sep 7, 2021

Hey @darrellwarde, any update on this?

I have many examples of places where I need to be able to sort results based on connected edges, for example, sort posts by the number of comments, or sort author by most recent post.

I attempted to work around the issue by adding a virtual field backed by a cypher query to return the result to sort on, hoping the GraphQL library would generate an order by augmentation for the property, but it seems it doesn't for fields backed by Cypher.

In some cases I'm able to mitigate by denormalizing the data and storing the count on the node as well, but this opens the opportunity for the property to be wrong which isn't great.

@morningcloud
Copy link

Following this issue for updates after posting to the discord channel. Looking forward to when this feature will be addressed.

@morningcloud
Copy link

Hi @darrellwarde, are the sorting-related features abandoned or is there any plan to proceed with the Pagination and Sorting 2.0 milestone?

Hi @rcbevans, I am interested to know if you managed to apply some reasonable alternative approaches to support the use case you mentioned for sorting

@darrellwarde
Copy link
Contributor

Definitely not abandoned, just a lot more to do first (updateOrCreate, root-level Interface and Union queries, etc.). And we're also more likely to implement sorting by aggregations first, as that has more utility than this. So don't expect anything too soon on this!

@MichaelCDormann
Copy link

Hi @darrellwarde, just wondering if this is still not abandoned. This would be a great feature to be able to use.

Currently if I need sorting on related node properties I have to give up on pagination, get all results, and sort on the client side. Curious if anyone has any better solutions.

@ghost
Copy link

ghost commented Aug 17, 2023

Hi @darrellwarde
Just wanted to know if this feature is still being developed?

We have a use case where we have to sort based on the properties of nested node in rich relationship.
It would be great if we have this feature.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants