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

Sorting on collection attribute #4

Closed
gmjordan opened this issue Dec 31, 2019 · 5 comments
Closed

Sorting on collection attribute #4

gmjordan opened this issue Dec 31, 2019 · 5 comments

Comments

@gmjordan
Copy link

Is sorting provided for on edge and vertex collections?

@colinfindlay
Copy link
Collaborator

Hi Greg, sorry for the delayed response - I've been on vacation.

There is currently no support for sorting. The AQL query that is generated basically outputs a list of paths which is probably not particularly useful for sorting, other than perhaps the top level root vertices.

I assume by the question you are looking to sort nested relationships so something like the following pseudo-GraphQL query

{ clients { name @sort age address { line1 line2 city @sort } }

i.e. Sort Clients by name, sort each client's address by city.

Is that right?

@gmjordan
Copy link
Author

yes, but top level sort would cover many use cases. For example, list of accounts ordered by account # or "friendly" name on the account, e.g. checking, savings ArangoDB-Community/arangodb-graphql-spring-boot-starter#1 , savings ArangoDB-Community/arangodb-graphql-spring-boot-starter#2

it would be ideal to have this with skip and limit, also, for pagination

@colinfindlay colinfindlay transferred this issue from ArangoDB-Community/arangodb-graphql-spring-boot-starter Jan 14, 2020
colinfindlay added a commit to colinfindlay/arangodb-graphql-java that referenced this issue Jan 14, 2020
@colinfindlay
Copy link
Collaborator

I've pushed a commit to my fork that should handle this.

The way it should work is if you declare arguments on your query operation named,"limit", "skip", or "sort" it will handle them accordingly.

Limit and Skip have the same meaning as the AQL documentation for Limit and Skip, and should be declared as Int type. Sort can be declared as a custom input type, as long as all its properties are scalar and can represent the String "ASC" or "DESC". An enum is a good choice here I think.

Example Schema:

enum SortDirection {
    ASC,
    DESC
}

input ClientSort {
    firstName: SortDirection
    lastName: SortDirection
}

type Query {
    getClients(limit: Int, skip: Int, sort: ClientSort): [Client]
}

Example Query

query {
  getClients(limit: 1, skip: 1, sort: { lastName: ASC }) {
    firstName
    lastName
  }
}

If you think that works for your use case let me know and I will open a PR with the community repo, and update the docs.

@gmjordan
Copy link
Author

gmjordan commented Jan 16, 2020

I've tested it locally and it works well. Nicely done.

rashtao added a commit that referenced this issue Jan 17, 2020
#4 - Adding support for Sort, Limit and Skip
@colinfindlay
Copy link
Collaborator

Functionality included in v1.2

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

No branches or pull requests

2 participants