Fetch Manga and Chapters in GQL (#555)

This commit is contained in:
Mitchell Syer
2023-05-24 06:31:07 -04:00
committed by GitHub
parent 603105e2ea
commit ff7ac8a785
4 changed files with 165 additions and 84 deletions

View File

@@ -3,10 +3,13 @@ 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.select
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import suwayomi.tachidesk.graphql.types.ChapterType
import suwayomi.tachidesk.manga.impl.Chapter
import suwayomi.tachidesk.manga.model.table.ChapterTable
import suwayomi.tachidesk.server.JavalinSetup.future
import java.time.Instant
import java.util.concurrent.CompletableFuture
@@ -63,7 +66,10 @@ class ChapterMutation {
}
}
fun updateChapter(dataFetchingEnvironment: DataFetchingEnvironment, input: UpdateChapterInput): CompletableFuture<UpdateChapterPayload> {
fun updateChapter(
dataFetchingEnvironment: DataFetchingEnvironment,
input: UpdateChapterInput
): CompletableFuture<UpdateChapterPayload> {
val (clientMutationId, id, patch) = input
updateChapters(listOf(id), patch)
@@ -76,7 +82,10 @@ class ChapterMutation {
}
}
fun updateChapters(dataFetchingEnvironment: DataFetchingEnvironment, input: UpdateChaptersInput): CompletableFuture<UpdateChaptersPayload> {
fun updateChapters(
dataFetchingEnvironment: DataFetchingEnvironment,
input: UpdateChaptersInput
): CompletableFuture<UpdateChaptersPayload> {
val (clientMutationId, ids, patch) = input
updateChapters(ids, patch)
@@ -88,4 +97,31 @@ class ChapterMutation {
)
}
}
data class FetchChaptersInput(
val clientMutationId: String? = null,
val mangaId: Int
)
data class FetchChaptersPayload(
val clientMutationId: String?,
val chapters: List<ChapterType>
)
fun fetchChapters(
input: FetchChaptersInput
): CompletableFuture<FetchChaptersPayload> {
val (clientMutationId, mangaId) = input
return future {
Chapter.fetchChapterList(mangaId)
}.thenApply {
val chapters = ChapterTable.select { ChapterTable.manga eq mangaId }
.orderBy(ChapterTable.sourceOrder)
.map { ChapterType(it) }
FetchChaptersPayload(
clientMutationId = clientMutationId,
chapters = chapters
)
}
}
}