Open6
Apollo Server+PrismaでのOrderBy

クエリでソート順を受け取ってPrismaに渡したい

prismaに渡すのは
const usersWithPosts = await prisma.user.findMany({
orderBy: [
{
role: 'desc',
},
{
name: 'desc',
},
],
include: {
posts: {
orderBy: {
title: 'desc',
},
select: {
title: true,
},
},
},
})
orderBy
にkeyにfield、valueにsortOrder
型のオブジェクトを渡す
export const SortOrder: {
asc: 'asc',
desc: 'desc'
};
簡単なのは当該オブジェクトをそのままクエリの方にすること

GitHubでの例
orderBy: IssueOrder
input IssueOrder {
"""
The direction in which to order issues by the specified field.
"""
direction: OrderDirection!
"""
The field in which to order issues by.
"""
field: IssueOrderField!
}
"""
Properties by which issue connections can be ordered.
"""
enum IssueOrderField {
"""
Order issues by comment count
"""
COMMENTS
"""
Order issues by creation time
"""
CREATED_AT
"""
Order issues by update time
"""
UPDATED_AT
}
"""
Possible directions in which to order a list of items when provided an `orderBy` argument.
"""
enum OrderDirection {
"""
Specifies an ascending order for a given `orderBy` argument.
"""
ASC
"""
Specifies a descending order for a given `orderBy` argument.
"""
DESC
}

参考

参考、ほぼ同様
enum Sort

呼び出し方は?複数のときは?