Skip to content

Commit 8b11749

Browse files
author
Travis CI User
committed
Fixes from CI
1 parent 66ab0c7 commit 8b11749

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

src/pages/postgraphile/make-add-pg-table-order-by-plugin.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ this function creates.
146146
`columnOrSqlFragment` is where the order value is specified, it becomes the
147147
first entry in the `OrderSpec` tuple defined above.
148148

149-
`uniqueOrOptions` define 1) whether the sort order is unique, and 2) how to sort null values when sorting by ascending and descending order. Only set `uniqueOrOptions` (or `unique`) to `true` if you can guarantee that the sort order is unique.
149+
`uniqueOrOptions` define 1) whether the sort order is unique, and 2) how to sort
150+
null values when sorting by ascending and descending order. Only set
151+
`uniqueOrOptions` (or `unique`) to `true` if you can guarantee that the sort
152+
order is unique.
150153

151154
As of v4.12, you can also customize how nulls are sorted:
152155

@@ -163,18 +166,27 @@ export interface OrderByAscDescOptions {
163166
nulls?: NullsSortMethod;
164167
}
165168
```
166-
The `nulls` option extends the `ORDER BY` clause of the SQL query with either `NULLS FIRST` or `NULLS LAST` according to the following rules:
169+
170+
The `nulls` option extends the `ORDER BY` clause of the SQL query with either
171+
`NULLS FIRST` or `NULLS LAST` according to the following rules:
172+
167173
- "first": specify `NULLS FIRST` for both ascending and descending;
168174
- "last": specify `NULLS LAST` for both ascending and descending;
169-
- "first-iff-ascending": specify `NULLS FIRST` when ordering by ascending, and `NULLS LAST` when ordering by descending;
170-
- "last-iff-ascending": specify `NULLS LAST` when ordering by ascending, and `NULLS FIRST` when ordering by descending;
171-
- (default) undefined: omit both `NULLS FIRST` and `NULLS LAST` in the order by clause for both ascending and descending, thus using the default ordering behavior.
175+
- "first-iff-ascending": specify `NULLS FIRST` when ordering by ascending, and
176+
`NULLS LAST` when ordering by descending;
177+
- "last-iff-ascending": specify `NULLS LAST` when ordering by ascending, and
178+
`NULLS FIRST` when ordering by descending;
179+
- (default) undefined: omit both `NULLS FIRST` and `NULLS LAST` in the order by
180+
clause for both ascending and descending, thus using the default ordering
181+
behavior.
182+
183+
For example, you may wish to create a plugin to sort movies by either top-rated
184+
or lowest-rated first (meaning the average of the movie's reviews):
172185

173-
For example, you may wish to create a plugin to sort movies by either top-rated or lowest-rated first (meaning the average of the movie's reviews):
174186
```ts
175187
const customOrderBy = orderByAscDesc(
176-
'RATING',
177-
(helpers) => {
188+
"RATING",
189+
helpers => {
178190
const { queryBuilder } = helpers;
179191

180192
const orderByFrag = sql.fragment`(
@@ -185,7 +197,14 @@ const customOrderBy = orderByAscDesc(
185197

186198
return orderByFrag;
187199
},
188-
{ nulls: 'last' },
200+
{ nulls: "last" }
189201
);
190202
```
191-
To get the top-rated movies, one would then use the `RATING_DESC` option in the GraphQL query. However, by default, `RATING_DESC` would put movies with no reviews (and thus an average of `null`) first, followed by the sorted movies. A movie with no ratings is not exactly what one thinks of when one hears "top-rated"! By specifying `{ nulls: 'last' }`, however, PostGraphile knows that this orderBy plugin should still show the movies without any reviews, but just put them at the end of the list.
203+
204+
To get the top-rated movies, one would then use the `RATING_DESC` option in the
205+
GraphQL query. However, by default, `RATING_DESC` would put movies with no
206+
reviews (and thus an average of `null`) first, followed by the sorted movies. A
207+
movie with no ratings is not exactly what one thinks of when one hears
208+
"top-rated"! By specifying `{ nulls: 'last' }`, however, PostGraphile knows that
209+
this orderBy plugin should still show the movies without any reviews, but just
210+
put them at the end of the list.

0 commit comments

Comments
 (0)