mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 10:54:38 -05:00
Sort gql queries by multiple columns (#963)
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package suwayomi.tachidesk.graphql.queries
|
package suwayomi.tachidesk.graphql.queries
|
||||||
|
|
||||||
|
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||||
import graphql.schema.DataFetchingEnvironment
|
import graphql.schema.DataFetchingEnvironment
|
||||||
import org.jetbrains.exposed.sql.Column
|
import org.jetbrains.exposed.sql.Column
|
||||||
@@ -27,6 +28,7 @@ import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareEntity
|
|||||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||||
|
import suwayomi.tachidesk.graphql.server.primitives.Order
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||||
@@ -80,6 +82,11 @@ class CategoryQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class CategoryOrder(
|
||||||
|
override val by: CategoryOrderBy,
|
||||||
|
override val byType: SortOrder? = null,
|
||||||
|
) : Order<CategoryOrderBy>
|
||||||
|
|
||||||
data class CategoryCondition(
|
data class CategoryCondition(
|
||||||
val id: Int? = null,
|
val id: Int? = null,
|
||||||
val order: Int? = null,
|
val order: Int? = null,
|
||||||
@@ -119,8 +126,17 @@ class CategoryQuery {
|
|||||||
fun categories(
|
fun categories(
|
||||||
condition: CategoryCondition? = null,
|
condition: CategoryCondition? = null,
|
||||||
filter: CategoryFilter? = null,
|
filter: CategoryFilter? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderBy: CategoryOrderBy? = null,
|
orderBy: CategoryOrderBy? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderByType: SortOrder? = null,
|
orderByType: SortOrder? = null,
|
||||||
|
order: List<CategoryOrder>? = null,
|
||||||
before: Cursor? = null,
|
before: Cursor? = null,
|
||||||
after: Cursor? = null,
|
after: Cursor? = null,
|
||||||
first: Int? = null,
|
first: Int? = null,
|
||||||
@@ -133,17 +149,15 @@ class CategoryQuery {
|
|||||||
|
|
||||||
res.applyOps(condition, filter)
|
res.applyOps(condition, filter)
|
||||||
|
|
||||||
if (orderBy != null || (last != null || before != null)) {
|
if (order != null || (last != null || before != null)) {
|
||||||
val orderByColumn = orderBy?.column ?: CategoryTable.id
|
val baseSort = listOf(CategoryOrder(CategoryOrderBy.ID, SortOrder.ASC))
|
||||||
val orderType = orderByType.maybeSwap(last ?: before)
|
val deprecatedSort = listOfNotNull(orderBy?.let { CategoryOrder(orderBy, orderByType) })
|
||||||
|
val actualSort = (order.orEmpty() + deprecatedSort + baseSort)
|
||||||
|
actualSort.forEach { (orderBy, orderByType) ->
|
||||||
|
val orderByColumn = orderBy.column
|
||||||
|
val orderType = orderByType.maybeSwap(last ?: before)
|
||||||
|
|
||||||
if (orderBy == CategoryOrderBy.ID || orderBy == null) {
|
|
||||||
res.orderBy(orderByColumn to orderType)
|
res.orderBy(orderByColumn to orderType)
|
||||||
} else {
|
|
||||||
res.orderBy(
|
|
||||||
orderByColumn to orderType,
|
|
||||||
CategoryTable.id to SortOrder.ASC,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,8 +168,8 @@ class CategoryQuery {
|
|||||||
res.applyBeforeAfter(
|
res.applyBeforeAfter(
|
||||||
before = before,
|
before = before,
|
||||||
after = after,
|
after = after,
|
||||||
orderBy = orderBy ?: CategoryOrderBy.ID,
|
orderBy = order?.firstOrNull()?.by ?: CategoryOrderBy.ID,
|
||||||
orderByType = orderByType,
|
orderByType = order?.firstOrNull()?.byType,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (first != null) {
|
if (first != null) {
|
||||||
@@ -167,7 +181,7 @@ class CategoryQuery {
|
|||||||
QueryResults(total, firstResult, lastResult, res.toList())
|
QueryResults(total, firstResult, lastResult, res.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
val getAsCursor: (CategoryType) -> Cursor = (orderBy ?: CategoryOrderBy.ID)::asCursor
|
val getAsCursor: (CategoryType) -> Cursor = (order?.firstOrNull()?.by ?: CategoryOrderBy.ID)::asCursor
|
||||||
|
|
||||||
val resultsAsType = queryResults.results.map { CategoryType(it) }
|
val resultsAsType = queryResults.results.map { CategoryType(it) }
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package suwayomi.tachidesk.graphql.queries
|
package suwayomi.tachidesk.graphql.queries
|
||||||
|
|
||||||
|
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||||
import graphql.schema.DataFetchingEnvironment
|
import graphql.schema.DataFetchingEnvironment
|
||||||
import org.jetbrains.exposed.sql.Column
|
import org.jetbrains.exposed.sql.Column
|
||||||
@@ -30,6 +31,7 @@ import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareEntity
|
|||||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||||
|
import suwayomi.tachidesk.graphql.server.primitives.Order
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||||
@@ -105,6 +107,11 @@ class ChapterQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class ChapterOrder(
|
||||||
|
override val by: ChapterOrderBy,
|
||||||
|
override val byType: SortOrder? = null,
|
||||||
|
) : Order<ChapterOrderBy>
|
||||||
|
|
||||||
data class ChapterCondition(
|
data class ChapterCondition(
|
||||||
val id: Int? = null,
|
val id: Int? = null,
|
||||||
val url: String? = null,
|
val url: String? = null,
|
||||||
@@ -195,8 +202,17 @@ class ChapterQuery {
|
|||||||
fun chapters(
|
fun chapters(
|
||||||
condition: ChapterCondition? = null,
|
condition: ChapterCondition? = null,
|
||||||
filter: ChapterFilter? = null,
|
filter: ChapterFilter? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderBy: ChapterOrderBy? = null,
|
orderBy: ChapterOrderBy? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderByType: SortOrder? = null,
|
orderByType: SortOrder? = null,
|
||||||
|
order: List<ChapterOrder>? = null,
|
||||||
before: Cursor? = null,
|
before: Cursor? = null,
|
||||||
after: Cursor? = null,
|
after: Cursor? = null,
|
||||||
first: Int? = null,
|
first: Int? = null,
|
||||||
@@ -217,17 +233,15 @@ class ChapterQuery {
|
|||||||
|
|
||||||
res.applyOps(condition, filter)
|
res.applyOps(condition, filter)
|
||||||
|
|
||||||
if (orderBy != null || (last != null || before != null)) {
|
if (order != null || (last != null || before != null)) {
|
||||||
val orderByColumn = orderBy?.column ?: ChapterTable.id
|
val baseSort = listOf(ChapterOrder(ChapterOrderBy.ID, SortOrder.ASC))
|
||||||
val orderType = orderByType.maybeSwap(last ?: before)
|
val deprecatedSort = listOfNotNull(orderBy?.let { ChapterOrder(orderBy, orderByType) })
|
||||||
|
val actualSort = (order.orEmpty() + deprecatedSort + baseSort)
|
||||||
|
actualSort.forEach { (orderBy, orderByType) ->
|
||||||
|
val orderByColumn = orderBy.column
|
||||||
|
val orderType = orderByType.maybeSwap(last ?: before)
|
||||||
|
|
||||||
if (orderBy == ChapterOrderBy.ID || orderBy == null) {
|
|
||||||
res.orderBy(orderByColumn to orderType)
|
res.orderBy(orderByColumn to orderType)
|
||||||
} else {
|
|
||||||
res.orderBy(
|
|
||||||
orderByColumn to orderType,
|
|
||||||
ChapterTable.id to SortOrder.ASC,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,8 +252,8 @@ class ChapterQuery {
|
|||||||
res.applyBeforeAfter(
|
res.applyBeforeAfter(
|
||||||
before = before,
|
before = before,
|
||||||
after = after,
|
after = after,
|
||||||
orderBy = orderBy ?: ChapterOrderBy.ID,
|
orderBy = order?.firstOrNull()?.by ?: ChapterOrderBy.ID,
|
||||||
orderByType = orderByType,
|
orderByType = order?.firstOrNull()?.byType,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (first != null) {
|
if (first != null) {
|
||||||
@@ -251,7 +265,7 @@ class ChapterQuery {
|
|||||||
QueryResults(total, firstResult, lastResult, res.toList())
|
QueryResults(total, firstResult, lastResult, res.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
val getAsCursor: (ChapterType) -> Cursor = (orderBy ?: ChapterOrderBy.ID)::asCursor
|
val getAsCursor: (ChapterType) -> Cursor = (order?.firstOrNull()?.by ?: ChapterOrderBy.ID)::asCursor
|
||||||
|
|
||||||
val resultsAsType = queryResults.results.map { ChapterType(it) }
|
val resultsAsType = queryResults.results.map { ChapterType(it) }
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package suwayomi.tachidesk.graphql.queries
|
package suwayomi.tachidesk.graphql.queries
|
||||||
|
|
||||||
|
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||||
import eu.kanade.tachiyomi.source.local.LocalSource
|
import eu.kanade.tachiyomi.source.local.LocalSource
|
||||||
import graphql.schema.DataFetchingEnvironment
|
import graphql.schema.DataFetchingEnvironment
|
||||||
@@ -28,6 +29,7 @@ import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompare
|
|||||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||||
|
import suwayomi.tachidesk.graphql.server.primitives.Order
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||||
@@ -81,6 +83,11 @@ class ExtensionQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class ExtensionOrder(
|
||||||
|
override val by: ExtensionOrderBy,
|
||||||
|
override val byType: SortOrder? = null,
|
||||||
|
) : Order<ExtensionOrderBy>
|
||||||
|
|
||||||
data class ExtensionCondition(
|
data class ExtensionCondition(
|
||||||
val repo: String? = null,
|
val repo: String? = null,
|
||||||
val apkName: String? = null,
|
val apkName: String? = null,
|
||||||
@@ -151,8 +158,17 @@ class ExtensionQuery {
|
|||||||
fun extensions(
|
fun extensions(
|
||||||
condition: ExtensionCondition? = null,
|
condition: ExtensionCondition? = null,
|
||||||
filter: ExtensionFilter? = null,
|
filter: ExtensionFilter? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderBy: ExtensionOrderBy? = null,
|
orderBy: ExtensionOrderBy? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderByType: SortOrder? = null,
|
orderByType: SortOrder? = null,
|
||||||
|
order: List<ExtensionOrder>? = null,
|
||||||
before: Cursor? = null,
|
before: Cursor? = null,
|
||||||
after: Cursor? = null,
|
after: Cursor? = null,
|
||||||
first: Int? = null,
|
first: Int? = null,
|
||||||
@@ -167,17 +183,15 @@ class ExtensionQuery {
|
|||||||
|
|
||||||
res.applyOps(condition, filter)
|
res.applyOps(condition, filter)
|
||||||
|
|
||||||
if (orderBy != null || (last != null || before != null)) {
|
if (order != null || (last != null || before != null)) {
|
||||||
val orderByColumn = orderBy?.column ?: ExtensionTable.pkgName
|
val baseSort = listOf(ExtensionOrder(ExtensionOrderBy.PKG_NAME, SortOrder.ASC))
|
||||||
val orderType = orderByType.maybeSwap(last ?: before)
|
val deprecatedSort = listOfNotNull(orderBy?.let { ExtensionOrder(orderBy, orderByType) })
|
||||||
|
val actualSort = (order.orEmpty() + deprecatedSort + baseSort)
|
||||||
|
actualSort.forEach { (orderBy, orderByType) ->
|
||||||
|
val orderByColumn = orderBy.column
|
||||||
|
val orderType = orderByType.maybeSwap(last ?: before)
|
||||||
|
|
||||||
if (orderBy == ExtensionOrderBy.PKG_NAME || orderBy == null) {
|
|
||||||
res.orderBy(orderByColumn to orderType)
|
res.orderBy(orderByColumn to orderType)
|
||||||
} else {
|
|
||||||
res.orderBy(
|
|
||||||
orderByColumn to orderType,
|
|
||||||
ExtensionTable.pkgName to SortOrder.ASC,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,8 +202,8 @@ class ExtensionQuery {
|
|||||||
res.applyBeforeAfter(
|
res.applyBeforeAfter(
|
||||||
before = before,
|
before = before,
|
||||||
after = after,
|
after = after,
|
||||||
orderBy = orderBy ?: ExtensionOrderBy.PKG_NAME,
|
orderBy = order?.firstOrNull()?.by ?: ExtensionOrderBy.PKG_NAME,
|
||||||
orderByType = orderByType,
|
orderByType = order?.firstOrNull()?.byType,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (first != null) {
|
if (first != null) {
|
||||||
@@ -201,7 +215,7 @@ class ExtensionQuery {
|
|||||||
QueryResults(total, firstResult, lastResult, res.toList())
|
QueryResults(total, firstResult, lastResult, res.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
val getAsCursor: (ExtensionType) -> Cursor = (orderBy ?: ExtensionOrderBy.PKG_NAME)::asCursor
|
val getAsCursor: (ExtensionType) -> Cursor = (order?.firstOrNull()?.by ?: ExtensionOrderBy.PKG_NAME)::asCursor
|
||||||
|
|
||||||
val resultsAsType = queryResults.results.map { ExtensionType(it) }
|
val resultsAsType = queryResults.results.map { ExtensionType(it) }
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package suwayomi.tachidesk.graphql.queries
|
package suwayomi.tachidesk.graphql.queries
|
||||||
|
|
||||||
|
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||||
import graphql.schema.DataFetchingEnvironment
|
import graphql.schema.DataFetchingEnvironment
|
||||||
import org.jetbrains.exposed.sql.Column
|
import org.jetbrains.exposed.sql.Column
|
||||||
@@ -30,6 +31,7 @@ import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
|||||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||||
import suwayomi.tachidesk.graphql.queries.util.distinctOn
|
import suwayomi.tachidesk.graphql.queries.util.distinctOn
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||||
|
import suwayomi.tachidesk.graphql.server.primitives.Order
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||||
@@ -89,6 +91,11 @@ class MangaQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class MangaOrder(
|
||||||
|
override val by: MangaOrderBy,
|
||||||
|
override val byType: SortOrder? = null,
|
||||||
|
) : Order<MangaOrderBy>
|
||||||
|
|
||||||
data class MangaCondition(
|
data class MangaCondition(
|
||||||
val id: Int? = null,
|
val id: Int? = null,
|
||||||
val sourceId: Long? = null,
|
val sourceId: Long? = null,
|
||||||
@@ -208,8 +215,17 @@ class MangaQuery {
|
|||||||
fun mangas(
|
fun mangas(
|
||||||
condition: MangaCondition? = null,
|
condition: MangaCondition? = null,
|
||||||
filter: MangaFilter? = null,
|
filter: MangaFilter? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderBy: MangaOrderBy? = null,
|
orderBy: MangaOrderBy? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderByType: SortOrder? = null,
|
orderByType: SortOrder? = null,
|
||||||
|
order: List<MangaOrder>? = null,
|
||||||
before: Cursor? = null,
|
before: Cursor? = null,
|
||||||
after: Cursor? = null,
|
after: Cursor? = null,
|
||||||
first: Int? = null,
|
first: Int? = null,
|
||||||
@@ -227,17 +243,15 @@ class MangaQuery {
|
|||||||
|
|
||||||
res.applyOps(condition, filter)
|
res.applyOps(condition, filter)
|
||||||
|
|
||||||
if (orderBy != null || (last != null || before != null)) {
|
if (order != null || (last != null || before != null)) {
|
||||||
val orderByColumn = orderBy?.column ?: MangaTable.id
|
val baseSort = listOf(MangaOrder(MangaOrderBy.ID, SortOrder.ASC))
|
||||||
val orderType = orderByType.maybeSwap(last ?: before)
|
val deprecatedSort = listOfNotNull(orderBy?.let { MangaOrder(orderBy, orderByType) })
|
||||||
|
val actualSort = (order.orEmpty() + deprecatedSort + baseSort)
|
||||||
|
actualSort.forEach { (orderBy, orderByType) ->
|
||||||
|
val orderByColumn = orderBy.column
|
||||||
|
val orderType = orderByType.maybeSwap(last ?: before)
|
||||||
|
|
||||||
if (orderBy == MangaOrderBy.ID || orderBy == null) {
|
|
||||||
res.orderBy(orderByColumn to orderType)
|
res.orderBy(orderByColumn to orderType)
|
||||||
} else {
|
|
||||||
res.orderBy(
|
|
||||||
orderByColumn to orderType,
|
|
||||||
MangaTable.id to SortOrder.ASC,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,8 +262,8 @@ class MangaQuery {
|
|||||||
res.applyBeforeAfter(
|
res.applyBeforeAfter(
|
||||||
before = before,
|
before = before,
|
||||||
after = after,
|
after = after,
|
||||||
orderBy = orderBy ?: MangaOrderBy.ID,
|
orderBy = order?.firstOrNull()?.by ?: MangaOrderBy.ID,
|
||||||
orderByType = orderByType,
|
orderByType = order?.firstOrNull()?.byType,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (first != null) {
|
if (first != null) {
|
||||||
@@ -261,7 +275,7 @@ class MangaQuery {
|
|||||||
QueryResults(total, firstResult, lastResult, res.toList())
|
QueryResults(total, firstResult, lastResult, res.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
val getAsCursor: (MangaType) -> Cursor = (orderBy ?: MangaOrderBy.ID)::asCursor
|
val getAsCursor: (MangaType) -> Cursor = (order?.firstOrNull()?.by ?: MangaOrderBy.ID)::asCursor
|
||||||
|
|
||||||
val resultsAsType = queryResults.results.map { MangaType(it) }
|
val resultsAsType = queryResults.results.map { MangaType(it) }
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package suwayomi.tachidesk.graphql.queries
|
package suwayomi.tachidesk.graphql.queries
|
||||||
|
|
||||||
|
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||||
import graphql.schema.DataFetchingEnvironment
|
import graphql.schema.DataFetchingEnvironment
|
||||||
import org.jetbrains.exposed.sql.Column
|
import org.jetbrains.exposed.sql.Column
|
||||||
@@ -24,6 +25,7 @@ import suwayomi.tachidesk.graphql.queries.filter.StringFilter
|
|||||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||||
|
import suwayomi.tachidesk.graphql.server.primitives.Order
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||||
@@ -72,6 +74,11 @@ class MetaQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class MetaOrder(
|
||||||
|
override val by: MetaOrderBy,
|
||||||
|
override val byType: SortOrder? = null,
|
||||||
|
) : Order<MetaOrderBy>
|
||||||
|
|
||||||
data class MetaCondition(
|
data class MetaCondition(
|
||||||
val key: String? = null,
|
val key: String? = null,
|
||||||
val value: String? = null,
|
val value: String? = null,
|
||||||
@@ -103,8 +110,17 @@ class MetaQuery {
|
|||||||
fun metas(
|
fun metas(
|
||||||
condition: MetaCondition? = null,
|
condition: MetaCondition? = null,
|
||||||
filter: MetaFilter? = null,
|
filter: MetaFilter? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderBy: MetaOrderBy? = null,
|
orderBy: MetaOrderBy? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderByType: SortOrder? = null,
|
orderByType: SortOrder? = null,
|
||||||
|
order: List<MetaOrder>? = null,
|
||||||
before: Cursor? = null,
|
before: Cursor? = null,
|
||||||
after: Cursor? = null,
|
after: Cursor? = null,
|
||||||
first: Int? = null,
|
first: Int? = null,
|
||||||
@@ -117,17 +133,15 @@ class MetaQuery {
|
|||||||
|
|
||||||
res.applyOps(condition, filter)
|
res.applyOps(condition, filter)
|
||||||
|
|
||||||
if (orderBy != null || (last != null || before != null)) {
|
if (order != null || (last != null || before != null)) {
|
||||||
val orderByColumn = orderBy?.column ?: GlobalMetaTable.key
|
val baseSort = listOf(MetaOrder(MetaOrderBy.KEY, SortOrder.ASC))
|
||||||
val orderType = orderByType.maybeSwap(last ?: before)
|
val deprecatedSort = listOfNotNull(orderBy?.let { MetaOrder(orderBy, orderByType) })
|
||||||
|
val actualSort = (order.orEmpty() + deprecatedSort + baseSort)
|
||||||
|
actualSort.forEach { (orderBy, orderByType) ->
|
||||||
|
val orderByColumn = orderBy.column
|
||||||
|
val orderType = orderByType.maybeSwap(last ?: before)
|
||||||
|
|
||||||
if (orderBy == MetaOrderBy.KEY || orderBy == null) {
|
|
||||||
res.orderBy(orderByColumn to orderType)
|
res.orderBy(orderByColumn to orderType)
|
||||||
} else {
|
|
||||||
res.orderBy(
|
|
||||||
orderByColumn to orderType,
|
|
||||||
GlobalMetaTable.key to SortOrder.ASC,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,8 +152,8 @@ class MetaQuery {
|
|||||||
res.applyBeforeAfter(
|
res.applyBeforeAfter(
|
||||||
before = before,
|
before = before,
|
||||||
after = after,
|
after = after,
|
||||||
orderBy = orderBy ?: MetaOrderBy.KEY,
|
orderBy = order?.firstOrNull()?.by ?: MetaOrderBy.KEY,
|
||||||
orderByType = orderByType,
|
orderByType = order?.firstOrNull()?.byType,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (first != null) {
|
if (first != null) {
|
||||||
@@ -151,7 +165,7 @@ class MetaQuery {
|
|||||||
QueryResults(total, firstResult, lastResult, res.toList())
|
QueryResults(total, firstResult, lastResult, res.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
val getAsCursor: (GlobalMetaType) -> Cursor = (orderBy ?: MetaOrderBy.KEY)::asCursor
|
val getAsCursor: (GlobalMetaType) -> Cursor = (order?.firstOrNull()?.by ?: MetaOrderBy.KEY)::asCursor
|
||||||
|
|
||||||
val resultsAsType = queryResults.results.map { GlobalMetaType(it) }
|
val resultsAsType = queryResults.results.map { GlobalMetaType(it) }
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package suwayomi.tachidesk.graphql.queries
|
package suwayomi.tachidesk.graphql.queries
|
||||||
|
|
||||||
|
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||||
import graphql.schema.DataFetchingEnvironment
|
import graphql.schema.DataFetchingEnvironment
|
||||||
import org.jetbrains.exposed.sql.Column
|
import org.jetbrains.exposed.sql.Column
|
||||||
@@ -27,6 +28,7 @@ import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareEntity
|
|||||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||||
|
import suwayomi.tachidesk.graphql.server.primitives.Order
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||||
@@ -80,6 +82,11 @@ class SourceQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class SourceOrder(
|
||||||
|
override val by: SourceOrderBy,
|
||||||
|
override val byType: SortOrder? = null,
|
||||||
|
) : Order<SourceOrderBy>
|
||||||
|
|
||||||
data class SourceCondition(
|
data class SourceCondition(
|
||||||
val id: Long? = null,
|
val id: Long? = null,
|
||||||
val name: String? = null,
|
val name: String? = null,
|
||||||
@@ -119,8 +126,17 @@ class SourceQuery {
|
|||||||
fun sources(
|
fun sources(
|
||||||
condition: SourceCondition? = null,
|
condition: SourceCondition? = null,
|
||||||
filter: SourceFilter? = null,
|
filter: SourceFilter? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderBy: SourceOrderBy? = null,
|
orderBy: SourceOrderBy? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderByType: SortOrder? = null,
|
orderByType: SortOrder? = null,
|
||||||
|
order: List<SourceOrder>? = null,
|
||||||
before: Cursor? = null,
|
before: Cursor? = null,
|
||||||
after: Cursor? = null,
|
after: Cursor? = null,
|
||||||
first: Int? = null,
|
first: Int? = null,
|
||||||
@@ -133,17 +149,15 @@ class SourceQuery {
|
|||||||
|
|
||||||
res.applyOps(condition, filter)
|
res.applyOps(condition, filter)
|
||||||
|
|
||||||
if (orderBy != null || (last != null || before != null)) {
|
if (order != null || (last != null || before != null)) {
|
||||||
val orderByColumn = orderBy?.column ?: SourceTable.id
|
val baseSort = listOf(SourceOrder(SourceOrderBy.ID, SortOrder.ASC))
|
||||||
val orderType = orderByType.maybeSwap(last ?: before)
|
val deprecatedSort = listOfNotNull(orderBy?.let { SourceOrder(orderBy, orderByType) })
|
||||||
|
val actualSort = (order.orEmpty() + deprecatedSort + baseSort)
|
||||||
|
actualSort.forEach { (orderBy, orderByType) ->
|
||||||
|
val orderByColumn = orderBy.column
|
||||||
|
val orderType = orderByType.maybeSwap(last ?: before)
|
||||||
|
|
||||||
if (orderBy == SourceOrderBy.ID || orderBy == null) {
|
|
||||||
res.orderBy(orderByColumn to orderType)
|
res.orderBy(orderByColumn to orderType)
|
||||||
} else {
|
|
||||||
res.orderBy(
|
|
||||||
orderByColumn to orderType,
|
|
||||||
SourceTable.id to SortOrder.ASC,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,8 +168,8 @@ class SourceQuery {
|
|||||||
res.applyBeforeAfter(
|
res.applyBeforeAfter(
|
||||||
before = before,
|
before = before,
|
||||||
after = after,
|
after = after,
|
||||||
orderBy = orderBy ?: SourceOrderBy.ID,
|
orderBy = order?.firstOrNull()?.by ?: SourceOrderBy.ID,
|
||||||
orderByType = orderByType,
|
orderByType = order?.firstOrNull()?.byType,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (first != null) {
|
if (first != null) {
|
||||||
@@ -169,7 +183,7 @@ class SourceQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val getAsCursor: (SourceType) -> Cursor = (orderBy ?: SourceOrderBy.ID)::asCursor
|
val getAsCursor: (SourceType) -> Cursor = (order?.firstOrNull()?.by ?: SourceOrderBy.ID)::asCursor
|
||||||
|
|
||||||
return SourceNodeList(
|
return SourceNodeList(
|
||||||
resultsAsType,
|
resultsAsType,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package suwayomi.tachidesk.graphql.queries
|
package suwayomi.tachidesk.graphql.queries
|
||||||
|
|
||||||
|
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||||
import graphql.schema.DataFetchingEnvironment
|
import graphql.schema.DataFetchingEnvironment
|
||||||
import org.jetbrains.exposed.sql.Column
|
import org.jetbrains.exposed.sql.Column
|
||||||
@@ -22,6 +23,7 @@ import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareEntity
|
|||||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
||||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||||
|
import suwayomi.tachidesk.graphql.server.primitives.Order
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||||
@@ -93,6 +95,11 @@ class TrackQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class TrackerOrder(
|
||||||
|
val by: TrackerOrderBy,
|
||||||
|
val byType: SortOrder? = null,
|
||||||
|
)
|
||||||
|
|
||||||
data class TrackerCondition(
|
data class TrackerCondition(
|
||||||
val id: Int? = null,
|
val id: Int? = null,
|
||||||
val name: String? = null,
|
val name: String? = null,
|
||||||
@@ -113,8 +120,17 @@ class TrackQuery {
|
|||||||
|
|
||||||
fun trackers(
|
fun trackers(
|
||||||
condition: TrackerCondition? = null,
|
condition: TrackerCondition? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderBy: TrackerOrderBy? = null,
|
orderBy: TrackerOrderBy? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderByType: SortOrder? = null,
|
orderByType: SortOrder? = null,
|
||||||
|
order: List<TrackerOrder>? = null,
|
||||||
before: Cursor? = null,
|
before: Cursor? = null,
|
||||||
after: Cursor? = null,
|
after: Cursor? = null,
|
||||||
first: Int? = null,
|
first: Int? = null,
|
||||||
@@ -135,35 +151,40 @@ class TrackQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orderBy != null || (last != null || before != null)) {
|
if (order != null || (last != null || before != null)) {
|
||||||
val orderType = orderByType.maybeSwap(last ?: before)
|
val baseSort = listOf(TrackerOrder(TrackerOrderBy.ID, SortOrder.ASC))
|
||||||
|
val deprecatedSort = listOfNotNull(orderBy?.let { TrackerOrder(orderBy, orderByType) })
|
||||||
|
val actualSort = (order.orEmpty() + deprecatedSort + baseSort)
|
||||||
|
actualSort.forEach { (orderBy, orderByType) ->
|
||||||
|
val orderType = orderByType.maybeSwap(last ?: before)
|
||||||
|
|
||||||
res =
|
res =
|
||||||
when (orderType) {
|
when (orderType) {
|
||||||
SortOrder.DESC, SortOrder.DESC_NULLS_FIRST, SortOrder.DESC_NULLS_LAST ->
|
SortOrder.DESC, SortOrder.DESC_NULLS_FIRST, SortOrder.DESC_NULLS_LAST ->
|
||||||
when (orderBy) {
|
when (orderBy) {
|
||||||
TrackerOrderBy.ID, null -> res.sortedByDescending { it.id }
|
TrackerOrderBy.ID -> res.sortedByDescending { it.id }
|
||||||
TrackerOrderBy.NAME -> res.sortedByDescending { it.name }
|
TrackerOrderBy.NAME -> res.sortedByDescending { it.name }
|
||||||
TrackerOrderBy.IS_LOGGED_IN -> res.sortedByDescending { it.isLoggedIn }
|
TrackerOrderBy.IS_LOGGED_IN -> res.sortedByDescending { it.isLoggedIn }
|
||||||
}
|
}
|
||||||
SortOrder.ASC, SortOrder.ASC_NULLS_FIRST, SortOrder.ASC_NULLS_LAST ->
|
SortOrder.ASC, SortOrder.ASC_NULLS_FIRST, SortOrder.ASC_NULLS_LAST ->
|
||||||
when (orderBy) {
|
when (orderBy) {
|
||||||
TrackerOrderBy.ID, null -> res.sortedBy { it.id }
|
TrackerOrderBy.ID -> res.sortedBy { it.id }
|
||||||
TrackerOrderBy.NAME -> res.sortedBy { it.name }
|
TrackerOrderBy.NAME -> res.sortedBy { it.name }
|
||||||
TrackerOrderBy.IS_LOGGED_IN -> res.sortedBy { it.isLoggedIn }
|
TrackerOrderBy.IS_LOGGED_IN -> res.sortedBy { it.isLoggedIn }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val total = res.size
|
val total = res.size
|
||||||
val firstResult = res.firstOrNull()
|
val firstResult = res.firstOrNull()
|
||||||
val lastResult = res.lastOrNull()
|
val lastResult = res.lastOrNull()
|
||||||
|
|
||||||
val realOrderBy = orderBy ?: TrackerOrderBy.ID
|
val realOrderBy = order?.firstOrNull()?.by ?: TrackerOrderBy.ID
|
||||||
if (after != null) {
|
if (after != null) {
|
||||||
res =
|
res =
|
||||||
res.filter {
|
res.filter {
|
||||||
when (orderByType) {
|
when (order?.firstOrNull()?.byType) {
|
||||||
SortOrder.DESC, SortOrder.DESC_NULLS_FIRST, SortOrder.DESC_NULLS_LAST -> realOrderBy.less(it, after)
|
SortOrder.DESC, SortOrder.DESC_NULLS_FIRST, SortOrder.DESC_NULLS_LAST -> realOrderBy.less(it, after)
|
||||||
null, SortOrder.ASC, SortOrder.ASC_NULLS_FIRST, SortOrder.ASC_NULLS_LAST -> realOrderBy.greater(it, after)
|
null, SortOrder.ASC, SortOrder.ASC_NULLS_FIRST, SortOrder.ASC_NULLS_LAST -> realOrderBy.greater(it, after)
|
||||||
}
|
}
|
||||||
@@ -171,7 +192,7 @@ class TrackQuery {
|
|||||||
} else if (before != null) {
|
} else if (before != null) {
|
||||||
res =
|
res =
|
||||||
res.filter {
|
res.filter {
|
||||||
when (orderByType) {
|
when (order?.firstOrNull()?.byType) {
|
||||||
SortOrder.DESC, SortOrder.DESC_NULLS_FIRST, SortOrder.DESC_NULLS_LAST -> realOrderBy.greater(it, before)
|
SortOrder.DESC, SortOrder.DESC_NULLS_FIRST, SortOrder.DESC_NULLS_LAST -> realOrderBy.greater(it, before)
|
||||||
null, SortOrder.ASC, SortOrder.ASC_NULLS_FIRST, SortOrder.ASC_NULLS_LAST -> realOrderBy.less(it, before)
|
null, SortOrder.ASC, SortOrder.ASC_NULLS_FIRST, SortOrder.ASC_NULLS_LAST -> realOrderBy.less(it, before)
|
||||||
}
|
}
|
||||||
@@ -187,7 +208,7 @@ class TrackQuery {
|
|||||||
QueryResults(total.toLong(), firstResult, lastResult, emptyList()) to res
|
QueryResults(total.toLong(), firstResult, lastResult, emptyList()) to res
|
||||||
}
|
}
|
||||||
|
|
||||||
val getAsCursor: (TrackerType) -> Cursor = (orderBy ?: TrackerOrderBy.ID)::asCursor
|
val getAsCursor: (TrackerType) -> Cursor = (order?.firstOrNull()?.by ?: TrackerOrderBy.ID)::asCursor
|
||||||
|
|
||||||
return TrackerNodeList(
|
return TrackerNodeList(
|
||||||
resultsAsType,
|
resultsAsType,
|
||||||
@@ -288,6 +309,11 @@ class TrackQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class TrackRecordOrder(
|
||||||
|
override val by: TrackRecordOrderBy,
|
||||||
|
override val byType: SortOrder? = null,
|
||||||
|
) : Order<TrackRecordOrderBy>
|
||||||
|
|
||||||
data class TrackRecordCondition(
|
data class TrackRecordCondition(
|
||||||
val id: Int? = null,
|
val id: Int? = null,
|
||||||
val mangaId: Int? = null,
|
val mangaId: Int? = null,
|
||||||
@@ -363,8 +389,17 @@ class TrackQuery {
|
|||||||
fun trackRecords(
|
fun trackRecords(
|
||||||
condition: TrackRecordCondition? = null,
|
condition: TrackRecordCondition? = null,
|
||||||
filter: TrackRecordFilter? = null,
|
filter: TrackRecordFilter? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderBy: TrackRecordOrderBy? = null,
|
orderBy: TrackRecordOrderBy? = null,
|
||||||
|
@GraphQLDeprecated(
|
||||||
|
"Replaced with order",
|
||||||
|
replaceWith = ReplaceWith("order"),
|
||||||
|
)
|
||||||
orderByType: SortOrder? = null,
|
orderByType: SortOrder? = null,
|
||||||
|
order: List<TrackRecordOrder>? = null,
|
||||||
before: Cursor? = null,
|
before: Cursor? = null,
|
||||||
after: Cursor? = null,
|
after: Cursor? = null,
|
||||||
first: Int? = null,
|
first: Int? = null,
|
||||||
@@ -377,17 +412,15 @@ class TrackQuery {
|
|||||||
|
|
||||||
res.applyOps(condition, filter)
|
res.applyOps(condition, filter)
|
||||||
|
|
||||||
if (orderBy != null || (last != null || before != null)) {
|
if (order != null || (last != null || before != null)) {
|
||||||
val orderByColumn = orderBy?.column ?: TrackRecordTable.id
|
val baseSort = listOf(TrackRecordOrder(TrackRecordOrderBy.ID, SortOrder.ASC))
|
||||||
val orderType = orderByType.maybeSwap(last ?: before)
|
val deprecatedSort = listOfNotNull(orderBy?.let { TrackRecordOrder(orderBy, orderByType) })
|
||||||
|
val actualSort = (order.orEmpty() + deprecatedSort + baseSort)
|
||||||
|
actualSort.forEach { (orderBy, orderByType) ->
|
||||||
|
val orderByColumn = orderBy.column
|
||||||
|
val orderType = orderByType.maybeSwap(last ?: before)
|
||||||
|
|
||||||
if (orderBy == TrackRecordOrderBy.ID || orderBy == null) {
|
|
||||||
res.orderBy(orderByColumn to orderType)
|
res.orderBy(orderByColumn to orderType)
|
||||||
} else {
|
|
||||||
res.orderBy(
|
|
||||||
orderByColumn to orderType,
|
|
||||||
TrackRecordTable.id to SortOrder.ASC,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,8 +431,8 @@ class TrackQuery {
|
|||||||
res.applyBeforeAfter(
|
res.applyBeforeAfter(
|
||||||
before = before,
|
before = before,
|
||||||
after = after,
|
after = after,
|
||||||
orderBy = orderBy ?: TrackRecordOrderBy.ID,
|
orderBy = order?.firstOrNull()?.by ?: TrackRecordOrderBy.ID,
|
||||||
orderByType = orderByType,
|
orderByType = order?.firstOrNull()?.byType,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (first != null) {
|
if (first != null) {
|
||||||
@@ -411,7 +444,7 @@ class TrackQuery {
|
|||||||
QueryResults(total, firstResult, lastResult, res.toList())
|
QueryResults(total, firstResult, lastResult, res.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
val getAsCursor: (TrackRecordType) -> Cursor = (orderBy ?: TrackRecordOrderBy.ID)::asCursor
|
val getAsCursor: (TrackRecordType) -> Cursor = (order?.firstOrNull()?.by ?: TrackRecordOrderBy.ID)::asCursor
|
||||||
|
|
||||||
val resultsAsType = queryResults.results.map { TrackRecordType(it) }
|
val resultsAsType = queryResults.results.map { TrackRecordType(it) }
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ interface OrderBy<T> {
|
|||||||
fun less(cursor: Cursor): Op<Boolean>
|
fun less(cursor: Cursor): Op<Boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Order<By : OrderBy<*>> {
|
||||||
|
val by: By
|
||||||
|
val byType: SortOrder?
|
||||||
|
}
|
||||||
|
|
||||||
fun SortOrder?.maybeSwap(value: Any?): SortOrder {
|
fun SortOrder?.maybeSwap(value: Any?): SortOrder {
|
||||||
return if (value != null) {
|
return if (value != null) {
|
||||||
when (this) {
|
when (this) {
|
||||||
|
|||||||
Reference in New Issue
Block a user