neo4j-graphql-java icon indicating copy to clipboard operation
neo4j-graphql-java copied to clipboard

Support for deep-sorting

Open Andy2003 opened this issue 5 years ago • 4 comments

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. This is related to #3 since the input of sorting will no longer be an enum.

Andy2003 avatar Sep 25 '19 10:09 Andy2003

Break it up into 2 steps

  1. input type for sorting
  2. optionally deep sorting

question: how do we manage the backwards compatibility if any.

jexp avatar Sep 25 '19 11:09 jexp

we can generate 2 arguments:

  1. deprecated enum
  2. new input field

Andy2003 avatar Sep 25 '19 11:09 Andy2003

Would need to align with neo4j-graphql-js

perhaps we can call the new field: sortBy or sort

/cc @johnymontana

jexp avatar Sep 25 '19 11:09 jexp

Break it up into 2 steps

  1. input type for sorting
  2. optionally deep sorting

for 1. I created issue #196

Andy2003 avatar Mar 27 '21 22:03 Andy2003