diff --git a/docs/graphql/manual/api-reference/query.rst b/docs/graphql/manual/api-reference/query.rst index d79718e5a5a66..4d95effe402cd 100644 --- a/docs/graphql/manual/api-reference/query.rst +++ b/docs/graphql/manual/api-reference/query.rst @@ -386,14 +386,18 @@ OrderByEnum #the order_by enum type enum order_by { - #in the ascending order + #in the ascending order, nulls last asc - #in the descending order - desc + #in the ascending order, nulls last + asc_nulls_last #in the ascending order, nulls first asc_nulls_first #in the descending order, nulls first + desc + #in the descending order, nulls first desc_nulls_first + #in the descending order, nulls last + desc_nulls_last } diff --git a/docs/graphql/manual/queries/sorting.rst b/docs/graphql/manual/queries/sorting.rst index f16b17658ee11..598277a448f71 100644 --- a/docs/graphql/manual/queries/sorting.rst +++ b/docs/graphql/manual/queries/sorting.rst @@ -6,8 +6,9 @@ objects too. The sort order (ascending vs. descending) is set by specifying ``asc`` or ``desc`` enum value for the column name in the ``order_by`` input object e.g. ``{name: desc}``. -By default, ``null`` values are returned at the end of the results. ``null`` values can be fetched first by specifying -``asc_nulls_first`` (ascending) and ``desc_nulls_first`` (descending) enum value e.g. ``{name: desc_nulls_first}``. +By default, for ascending ordering ``null`` values are returned at the end of the results and for descending ordering ``null`` +values are returned at the start of the results. ``null`` values can be fetched first on ascending ordering by specifying +``asc_nulls_first`` and last on descending ordering by specifying ``desc_nulls_last`` enum value e.g. ``{name: desc_nulls_last}``. The ``order_by`` argument takes an array of objects to allow sorting by multiple columns. @@ -29,14 +30,18 @@ The ``order_by`` argument takes an array of objects to allow sorting by multiple #the order_by enum type enum order_by { - #in the ascending order + #in the ascending order, nulls last asc - #in the descending order - desc + #in the ascending order, nulls last + asc_nulls_last #in the ascending order, nulls first asc_nulls_first #in the descending order, nulls first + desc + #in the descending order, nulls first desc_nulls_first + #in the descending order, nulls last + desc_nulls_last } .. Note:: diff --git a/server/src-lib/Hasura/GraphQL/Resolve/Select.hs b/server/src-lib/Hasura/GraphQL/Resolve/Select.hs index ddd6433b1cb2f..b1d6c6b320309 100644 --- a/server/src-lib/Hasura/GraphQL/Resolve/Select.hs +++ b/server/src-lib/Hasura/GraphQL/Resolve/Select.hs @@ -156,9 +156,11 @@ parseOrderByEnum -> m (S.OrderType, S.NullsOrder) parseOrderByEnum = \case G.EnumValue "asc" -> return (S.OTAsc, S.NLast) - G.EnumValue "desc" -> return (S.OTDesc, S.NLast) + G.EnumValue "asc_nulls_last" -> return (S.OTAsc, S.NLast) G.EnumValue "asc_nulls_first" -> return (S.OTAsc, S.NFirst) + G.EnumValue "desc" -> return (S.OTDesc, S.NFirst) G.EnumValue "desc_nulls_first" -> return (S.OTDesc, S.NFirst) + G.EnumValue "desc_nulls_last" -> return (S.OTDesc, S.NLast) G.EnumValue v -> throw500 $ "enum value " <> showName v <> " not found in type order_by" diff --git a/server/src-lib/Hasura/GraphQL/Schema.hs b/server/src-lib/Hasura/GraphQL/Schema.hs index 77c45602feac0..fcdb9c7841aca 100644 --- a/server/src-lib/Hasura/GraphQL/Schema.hs +++ b/server/src-lib/Hasura/GraphQL/Schema.hs @@ -1063,14 +1063,20 @@ ordByEnumTy = [ ( "asc" , "in the ascending order, nulls last" ), - ( "desc" - , "in the descending order, nulls last" + ( "asc_nulls_last" + , "in the ascending order, nulls last" ), ( "asc_nulls_first" , "in the ascending order, nulls first" ), + ( "desc" + , "in the descending order, nulls first" + ), ( "desc_nulls_first" - , "in the ascending order, nulls first" + , "in the descending order, nulls first" + ), + ( "desc_nulls_last" + , "in the descending order, nulls last" ) ]