@ORDERBYディレクティブ
@orderbyディレクティブは、指定されたフィールドにorderby句を指定します。
このディレクティブには、出力を順序付けするためのSQL式を指定できるSQLという1つの引数があります。@orderbyディレクティブは、配列を返すオブジェクト・フィールドで使用する必要があります。
SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
driver {
id: driver_id
name
points
bestPerformances: driver_race_map (
check: {
position: {_lte: 3}
}
) @orderby(sql: "position asc")
{
position
race @unnest {
race: name
}
}
}
');
前述の例では、ドライバの詳細と、ドライバが3位以内で終了したレースを順位の順で取得します:
DATA
--------------------------------------------------------------------------------
{
"id" : 101,
"name" : "Lando Norris",
"points" : 282,
"bestPerformances" :
[
{
"position" : 1,
"race" : "Miami Grand Prix"
},
{
"position" : 1,
"race" : "Abu Dhabi Grand Prix"
},
{
"position" : 1,
"race" : "Singapore Grand Prix"
},
{
"position" : 1,
"race" : "Dutch Grand Prix"
},
{
"position" : 2,
"race" : "Australian Grand Prix"
},
{
"position" : 2,
"race" : "Qatar Grand Prix"
},
{
"position" : 2,
"race" : "Azerbaijan Grand Prix"
},
{
"position" : 2,
"race" : "British Grand Prix"
},
{
"position" : 2,
"race" : "Emilia Romagna Grand Prix"
},
{
"position" : 3,
"race" : "Spanish Grand Prix"
},
{
"position" : 3,
"race" : "Belgian Grand Prix"
},
{
"position" : 3,
"race" : "United States Grand Prix"
},
{
"position" : 3,
"race" : "São Paulo Grand Prix"
}
]
}
{
"id" : 102,
"name" : "Oscar Piastri",
"points" : 384,
"bestPerformances" :
[
{
"position" : 1,
"race" : "Hungarian Grand Prix"
},
{
"position" : 1,
"race" : "Azerbaijan Grand Prix"
},
{
"position" : 3,
"race" : "Japanese Grand Prix"
}
]
}
.......................................
.......................................
20 rows selected.