Update graphqlkotlin to v10 alpha (major) (#1923)

* Update graphqlkotlin to v9

* Update to the v10 alpha due to nullability issues in v9

* Fixes

* Remove asDataFetcherResult

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Syer10 <syer10@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2026-05-10 19:01:34 -04:00
committed by GitHub
parent dff66547b4
commit edf376e3dd
29 changed files with 1197 additions and 1313 deletions

View File

@@ -1,3 +1,5 @@
@file:Suppress("RedundantNullableReturnType", "unused")
package suwayomi.tachidesk.graphql.mutations
import androidx.preference.CheckBoxPreference
@@ -5,7 +7,6 @@ import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.MultiSelectListPreference
import androidx.preference.SwitchPreferenceCompat
import graphql.execution.DataFetcherResult
import org.jetbrains.exposed.sql.LikePattern
import org.jetbrains.exposed.sql.Op
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
@@ -16,7 +17,6 @@ import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.or
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.asDataFetcherResult
import suwayomi.tachidesk.graphql.directives.RequireAuth
import suwayomi.tachidesk.graphql.types.FilterChange
import suwayomi.tachidesk.graphql.types.MangaType
@@ -47,14 +47,12 @@ class SourceMutation {
)
@RequireAuth
fun setSourceMeta(input: SetSourceMetaInput): DataFetcherResult<SetSourceMetaPayload?> {
fun setSourceMeta(input: SetSourceMetaInput): SetSourceMetaPayload? {
val (clientMutationId, meta) = input
return asDataFetcherResult {
Source.modifyMeta(meta.sourceId, meta.key, meta.value)
Source.modifyMeta(meta.sourceId, meta.key, meta.value)
SetSourceMetaPayload(clientMutationId, meta)
}
return SetSourceMetaPayload(clientMutationId, meta)
}
data class DeleteSourceMetaInput(
@@ -70,38 +68,36 @@ class SourceMutation {
)
@RequireAuth
fun deleteSourceMeta(input: DeleteSourceMetaInput): DataFetcherResult<DeleteSourceMetaPayload?> {
fun deleteSourceMeta(input: DeleteSourceMetaInput): DeleteSourceMetaPayload? {
val (clientMutationId, sourceId, key) = input
return asDataFetcherResult {
val (meta, source) =
transaction {
val meta =
SourceMetaTable
val (meta, source) =
transaction {
val meta =
SourceMetaTable
.selectAll()
.where { (SourceMetaTable.ref eq sourceId) and (SourceMetaTable.key eq key) }
.firstOrNull()
SourceMetaTable.deleteWhere { (SourceMetaTable.ref eq sourceId) and (SourceMetaTable.key eq key) }
val source =
transaction {
SourceTable
.selectAll()
.where { (SourceMetaTable.ref eq sourceId) and (SourceMetaTable.key eq key) }
.where { SourceTable.id eq sourceId }
.firstOrNull()
?.let { SourceType(it) }
}
SourceMetaTable.deleteWhere { (SourceMetaTable.ref eq sourceId) and (SourceMetaTable.key eq key) }
if (meta != null) {
SourceMetaType(meta)
} else {
null
} to source
}
val source =
transaction {
SourceTable
.selectAll()
.where { SourceTable.id eq sourceId }
.firstOrNull()
?.let { SourceType(it) }
}
if (meta != null) {
SourceMetaType(meta)
} else {
null
} to source
}
DeleteSourceMetaPayload(clientMutationId, meta, source)
}
return DeleteSourceMetaPayload(clientMutationId, meta, source)
}
data class SetSourceMetasItem(
@@ -121,43 +117,41 @@ class SourceMutation {
)
@RequireAuth
fun setSourceMetas(input: SetSourceMetasInput): DataFetcherResult<SetSourceMetasPayload?> {
fun setSourceMetas(input: SetSourceMetasInput): SetSourceMetasPayload? {
val (clientMutationId, items) = input
return asDataFetcherResult {
val metaBySourceId =
items
.flatMap { item ->
val metaMap = item.metas.associate { it.key to it.value }
item.sourceIds.map { sourceId -> sourceId to metaMap }
}.groupBy({ it.first }, { it.second })
.mapValues { (_, maps) -> maps.reduce { acc, map -> acc + map } }
val metaBySourceId =
items
.flatMap { item ->
val metaMap = item.metas.associate { it.key to it.value }
item.sourceIds.map { sourceId -> sourceId to metaMap }
}.groupBy({ it.first }, { it.second })
.mapValues { (_, maps) -> maps.reduce { acc, map -> acc + map } }
Source.modifySourceMetas(metaBySourceId)
Source.modifySourceMetas(metaBySourceId)
val allSourceIds = metaBySourceId.keys
val allMetaKeys = metaBySourceId.values.flatMap { it.keys }.distinct()
val allSourceIds = metaBySourceId.keys
val allMetaKeys = metaBySourceId.values.flatMap { it.keys }.distinct()
val (updatedMetas, sources) =
transaction {
val updatedMetas =
SourceMetaTable
.selectAll()
.where { (SourceMetaTable.ref inList allSourceIds) and (SourceMetaTable.key inList allMetaKeys) }
.map { SourceMetaType(it) }
val (updatedMetas, sources) =
transaction {
val updatedMetas =
SourceMetaTable
.selectAll()
.where { (SourceMetaTable.ref inList allSourceIds) and (SourceMetaTable.key inList allMetaKeys) }
.map { SourceMetaType(it) }
val sources =
SourceTable
.selectAll()
.where { SourceTable.id inList allSourceIds }
.mapNotNull { SourceType(it) }
.distinctBy { it.id }
val sources =
SourceTable
.selectAll()
.where { SourceTable.id inList allSourceIds }
.mapNotNull { SourceType(it) }
.distinctBy { it.id }
updatedMetas to sources
}
updatedMetas to sources
}
SetSourceMetasPayload(clientMutationId, updatedMetas, sources)
}
return SetSourceMetasPayload(clientMutationId, updatedMetas, sources)
}
data class DeleteSourceMetasItem(
@@ -178,64 +172,62 @@ class SourceMutation {
)
@RequireAuth
fun deleteSourceMetas(input: DeleteSourceMetasInput): DataFetcherResult<DeleteSourceMetasPayload?> {
fun deleteSourceMetas(input: DeleteSourceMetasInput): DeleteSourceMetasPayload? {
val (clientMutationId, items) = input
return asDataFetcherResult {
items.forEach { item ->
require(!item.keys.isNullOrEmpty() || !item.prefixes.isNullOrEmpty()) {
"Either 'keys' or 'prefixes' must be provided for each item"
items.forEach { item ->
require(!item.keys.isNullOrEmpty() || !item.prefixes.isNullOrEmpty()) {
"Either 'keys' or 'prefixes' must be provided for each item"
}
}
val (allDeletedMetas, allSourceIds) =
transaction {
val deletedMetas = mutableListOf<SourceMetaType>()
val sourceIds = mutableSetOf<Long>()
items.forEach { item ->
val keyCondition: Op<Boolean>? =
item.keys?.takeIf { it.isNotEmpty() }?.let { SourceMetaTable.key inList it }
val prefixCondition: Op<Boolean>? =
item.prefixes
?.filter { it.isNotEmpty() }
?.map { (SourceMetaTable.key like LikePattern("$it%")) as Op<Boolean> }
?.reduceOrNull { acc, op -> acc or op }
val metaKeyCondition =
if (keyCondition != null && prefixCondition != null) {
keyCondition or prefixCondition
} else {
keyCondition ?: prefixCondition!!
}
val condition = (SourceMetaTable.ref inList item.sourceIds) and metaKeyCondition
deletedMetas +=
SourceMetaTable
.selectAll()
.where { condition }
.map { SourceMetaType(it) }
SourceMetaTable.deleteWhere { condition }
sourceIds += item.sourceIds
}
deletedMetas to sourceIds
}
val (allDeletedMetas, allSourceIds) =
transaction {
val deletedMetas = mutableListOf<SourceMetaType>()
val sourceIds = mutableSetOf<Long>()
val sources =
transaction {
SourceTable
.selectAll()
.where { SourceTable.id inList allSourceIds }
.mapNotNull { SourceType(it) }
.distinctBy { it.id }
}
items.forEach { item ->
val keyCondition: Op<Boolean>? =
item.keys?.takeIf { it.isNotEmpty() }?.let { SourceMetaTable.key inList it }
val prefixCondition: Op<Boolean>? =
item.prefixes
?.filter { it.isNotEmpty() }
?.map { (SourceMetaTable.key like LikePattern("$it%")) as Op<Boolean> }
?.reduceOrNull { acc, op -> acc or op }
val metaKeyCondition =
if (keyCondition != null && prefixCondition != null) {
keyCondition or prefixCondition
} else {
keyCondition ?: prefixCondition!!
}
val condition = (SourceMetaTable.ref inList item.sourceIds) and metaKeyCondition
deletedMetas +=
SourceMetaTable
.selectAll()
.where { condition }
.map { SourceMetaType(it) }
SourceMetaTable.deleteWhere { condition }
sourceIds += item.sourceIds
}
deletedMetas to sourceIds
}
val sources =
transaction {
SourceTable
.selectAll()
.where { SourceTable.id inList allSourceIds }
.mapNotNull { SourceType(it) }
.distinctBy { it.id }
}
DeleteSourceMetasPayload(clientMutationId, allDeletedMetas, sources)
}
return DeleteSourceMetasPayload(clientMutationId, allDeletedMetas, sources)
}
enum class FetchSourceMangaType {
@@ -260,50 +252,48 @@ class SourceMutation {
)
@RequireAuth
fun fetchSourceManga(input: FetchSourceMangaInput): CompletableFuture<DataFetcherResult<FetchSourceMangaPayload?>> {
fun fetchSourceManga(input: FetchSourceMangaInput): CompletableFuture<FetchSourceMangaPayload?> {
val (clientMutationId, sourceId, type, page, query, filters) = input
return future {
asDataFetcherResult {
val source = GetCatalogueSource.getCatalogueSourceOrNull(sourceId)!!
val mangasPage =
when (type) {
FetchSourceMangaType.SEARCH -> {
source.getSearchManga(
page = page,
query = query.orEmpty(),
filters = updateFilterList(source, filters),
)
}
FetchSourceMangaType.POPULAR -> {
source.getPopularManga(page)
}
FetchSourceMangaType.LATEST -> {
if (!source.supportsLatest) throw Exception("Source does not support latest")
source.getLatestUpdates(page)
}
val source = GetCatalogueSource.getCatalogueSourceOrNull(sourceId)!!
val mangasPage =
when (type) {
FetchSourceMangaType.SEARCH -> {
source.getSearchManga(
page = page,
query = query.orEmpty(),
filters = updateFilterList(source, filters),
)
}
val mangaIds = mangasPage.insertOrUpdate(sourceId)
val mangas =
transaction {
MangaTable
.selectAll()
.where { MangaTable.id inList mangaIds }
.map { MangaType(it) }
}.sortedBy {
mangaIds.indexOf(it.id)
FetchSourceMangaType.POPULAR -> {
source.getPopularManga(page)
}
FetchSourceMangaPayload(
clientMutationId = clientMutationId,
mangas = mangas,
hasNextPage = mangasPage.hasNextPage,
)
}
FetchSourceMangaType.LATEST -> {
if (!source.supportsLatest) throw Exception("Source does not support latest")
source.getLatestUpdates(page)
}
}
val mangaIds = mangasPage.insertOrUpdate(sourceId)
val mangas =
transaction {
MangaTable
.selectAll()
.where { MangaTable.id inList mangaIds }
.map { MangaType(it) }
}.sortedBy {
mangaIds.indexOf(it.id)
}
FetchSourceMangaPayload(
clientMutationId = clientMutationId,
mangas = mangas,
hasNextPage = mangasPage.hasNextPage,
)
}
}
@@ -329,29 +319,27 @@ class SourceMutation {
)
@RequireAuth
fun updateSourcePreference(input: UpdateSourcePreferenceInput): DataFetcherResult<UpdateSourcePreferencePayload?> {
fun updateSourcePreference(input: UpdateSourcePreferenceInput): UpdateSourcePreferencePayload? {
val (clientMutationId, sourceId, change) = input
return asDataFetcherResult {
Source.setSourcePreference(sourceId, change.position, "") { preference ->
when (preference) {
is SwitchPreferenceCompat -> change.switchState
is CheckBoxPreference -> change.checkBoxState
is EditTextPreference -> change.editTextState
is ListPreference -> change.listState
is MultiSelectListPreference -> change.multiSelectState?.toSet()
else -> throw RuntimeException("sealed class cannot have more subtypes!")
} ?: throw Exception("Expected change to ${preference::class.simpleName}")
}
UpdateSourcePreferencePayload(
clientMutationId = clientMutationId,
preferences = Source.getSourcePreferencesRaw(sourceId).map { preferenceOf(it) },
source =
transaction {
SourceType(SourceTable.selectAll().where { SourceTable.id eq sourceId }.first())!!
},
)
Source.setSourcePreference(sourceId, change.position, "") { preference ->
when (preference) {
is SwitchPreferenceCompat -> change.switchState
is CheckBoxPreference -> change.checkBoxState
is EditTextPreference -> change.editTextState
is ListPreference -> change.listState
is MultiSelectListPreference -> change.multiSelectState?.toSet()
else -> throw RuntimeException("sealed class cannot have more subtypes!")
} ?: throw Exception("Expected change to ${preference::class.simpleName}")
}
return UpdateSourcePreferencePayload(
clientMutationId = clientMutationId,
preferences = Source.getSourcePreferencesRaw(sourceId).map { preferenceOf(it) },
source =
transaction {
SourceType(SourceTable.selectAll().where { SourceTable.id eq sourceId }.first())!!
},
)
}
}