Don't use data fetchers in mutations (#559)

This commit is contained in:
Mitchell Syer
2023-05-26 19:39:31 -04:00
committed by GitHub
parent 2230796504
commit a81d01d2e3
2 changed files with 32 additions and 32 deletions

View File

@@ -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,35 +68,37 @@ 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())
clientMutationId = clientMutationId,
chapter = chapter
)
} }
return UpdateChapterPayload(
clientMutationId = clientMutationId,
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) }
clientMutationId = clientMutationId,
chapters = chapters
)
} }
return UpdateChaptersPayload(
clientMutationId = clientMutationId,
chapters = chapters
)
} }
data class FetchChaptersInput( data class FetchChaptersInput(

View File

@@ -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,30 +58,34 @@ 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())
clientMutationId = clientMutationId,
manga = manga
)
} }
return UpdateMangaPayload(
clientMutationId = clientMutationId,
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) }
clientMutationId = clientMutationId,
mangas = mangas
)
} }
return UpdateMangasPayload(
clientMutationId = clientMutationId,
mangas = mangas
)
} }
data class FetchMangaInput( data class FetchMangaInput(