mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -05:00
Don't use data fetchers in mutations (#559)
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
package suwayomi.tachidesk.graphql.mutations
|
package suwayomi.tachidesk.graphql.mutations
|
||||||
|
|
||||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
|
||||||
import com.expediagroup.graphql.server.extensions.getValuesFromDataLoader
|
|
||||||
import graphql.schema.DataFetchingEnvironment
|
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
import org.jetbrains.exposed.sql.and
|
import org.jetbrains.exposed.sql.and
|
||||||
import org.jetbrains.exposed.sql.deleteWhere
|
import org.jetbrains.exposed.sql.deleteWhere
|
||||||
@@ -71,36 +68,38 @@ class ChapterMutation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateChapter(
|
fun updateChapter(
|
||||||
dataFetchingEnvironment: DataFetchingEnvironment,
|
|
||||||
input: UpdateChapterInput
|
input: UpdateChapterInput
|
||||||
): CompletableFuture<UpdateChapterPayload> {
|
): UpdateChapterPayload {
|
||||||
val (clientMutationId, id, patch) = input
|
val (clientMutationId, id, patch) = input
|
||||||
|
|
||||||
updateChapters(listOf(id), patch)
|
updateChapters(listOf(id), patch)
|
||||||
|
|
||||||
return dataFetchingEnvironment.getValueFromDataLoader<Int, ChapterType>("ChapterDataLoader", id).thenApply { chapter ->
|
val chapter = transaction {
|
||||||
UpdateChapterPayload(
|
ChapterType(ChapterTable.select { ChapterTable.id eq id }.first())
|
||||||
|
}
|
||||||
|
|
||||||
|
return UpdateChapterPayload(
|
||||||
clientMutationId = clientMutationId,
|
clientMutationId = clientMutationId,
|
||||||
chapter = chapter
|
chapter = chapter
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun updateChapters(
|
fun updateChapters(
|
||||||
dataFetchingEnvironment: DataFetchingEnvironment,
|
|
||||||
input: UpdateChaptersInput
|
input: UpdateChaptersInput
|
||||||
): CompletableFuture<UpdateChaptersPayload> {
|
): UpdateChaptersPayload {
|
||||||
val (clientMutationId, ids, patch) = input
|
val (clientMutationId, ids, patch) = input
|
||||||
|
|
||||||
updateChapters(ids, patch)
|
updateChapters(ids, patch)
|
||||||
|
|
||||||
return dataFetchingEnvironment.getValuesFromDataLoader<Int, ChapterType>("ChapterDataLoader", ids).thenApply { chapters ->
|
val chapters = transaction {
|
||||||
UpdateChaptersPayload(
|
ChapterTable.select { ChapterTable.id inList ids }.map { ChapterType(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
return UpdateChaptersPayload(
|
||||||
clientMutationId = clientMutationId,
|
clientMutationId = clientMutationId,
|
||||||
chapters = chapters
|
chapters = chapters
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
data class FetchChaptersInput(
|
data class FetchChaptersInput(
|
||||||
val clientMutationId: String? = null,
|
val clientMutationId: String? = null,
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package suwayomi.tachidesk.graphql.mutations
|
package suwayomi.tachidesk.graphql.mutations
|
||||||
|
|
||||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
|
||||||
import com.expediagroup.graphql.server.extensions.getValuesFromDataLoader
|
|
||||||
import graphql.schema.DataFetchingEnvironment
|
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
import org.jetbrains.exposed.sql.and
|
import org.jetbrains.exposed.sql.and
|
||||||
import org.jetbrains.exposed.sql.deleteWhere
|
import org.jetbrains.exposed.sql.deleteWhere
|
||||||
@@ -61,31 +58,35 @@ class MangaMutation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateManga(dataFetchingEnvironment: DataFetchingEnvironment, input: UpdateMangaInput): CompletableFuture<UpdateMangaPayload> {
|
fun updateManga(input: UpdateMangaInput): UpdateMangaPayload {
|
||||||
val (clientMutationId, id, patch) = input
|
val (clientMutationId, id, patch) = input
|
||||||
|
|
||||||
updateMangas(listOf(id), patch)
|
updateMangas(listOf(id), patch)
|
||||||
|
|
||||||
return dataFetchingEnvironment.getValueFromDataLoader<Int, MangaType>("MangaDataLoader", id).thenApply { manga ->
|
val manga = transaction {
|
||||||
UpdateMangaPayload(
|
MangaType(MangaTable.select { MangaTable.id eq id }.first())
|
||||||
|
}
|
||||||
|
|
||||||
|
return UpdateMangaPayload(
|
||||||
clientMutationId = clientMutationId,
|
clientMutationId = clientMutationId,
|
||||||
manga = manga
|
manga = manga
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun updateMangas(dataFetchingEnvironment: DataFetchingEnvironment, input: UpdateMangasInput): CompletableFuture<UpdateMangasPayload> {
|
fun updateMangas(input: UpdateMangasInput): UpdateMangasPayload {
|
||||||
val (clientMutationId, ids, patch) = input
|
val (clientMutationId, ids, patch) = input
|
||||||
|
|
||||||
updateMangas(ids, patch)
|
updateMangas(ids, patch)
|
||||||
|
|
||||||
return dataFetchingEnvironment.getValuesFromDataLoader<Int, MangaType>("MangaDataLoader", ids).thenApply { mangas ->
|
val mangas = transaction {
|
||||||
UpdateMangasPayload(
|
MangaTable.select { MangaTable.id inList ids }.map { MangaType(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
return UpdateMangasPayload(
|
||||||
clientMutationId = clientMutationId,
|
clientMutationId = clientMutationId,
|
||||||
mangas = mangas
|
mangas = mangas
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
data class FetchMangaInput(
|
data class FetchMangaInput(
|
||||||
val clientMutationId: String? = null,
|
val clientMutationId: String? = null,
|
||||||
|
|||||||
Reference in New Issue
Block a user