Advanced Sorting
With Prisma, it is possible to return lists of elements that are sorted (_ordered_) according to specific criteria.
Sorting
With Prisma, it is possible to return lists of elements that are sorted (ordered) according to
specific criteria. For example, you can order the list of Links alphabetically by their url or
description. For the Hacker News API, you’ll leave it up to the client to decide how exactly it
should be sorted and thus include all the ordering options from the Prisma API in the API of your
GraphQL server. You can do so by creating an
input type and an enum to represent
the ordering options.
Add the following enum definition to your GraphQL schema:
This represents the various ways that the list of Link elements can be sorted (asc = ascending,
desc = descending).
Now, adjust the Query.feed field SDL again to include the orderBy argument:
The implementation of the resolver is similar to what you just did with the pagination API.
Update the implementation of the feed resolver, change the imports and pass the orderBy argument
along to Prisma:
Awesome! Here’s a query that sorts the returned links by their creation dates: