Skip to content

Commit

Permalink
Support partial mutation responses (#954)
Browse files Browse the repository at this point in the history
In case e.g. a mutation was made which looked like this

myMutation {
  mutationA { ... }
  mutationB { ... }
  mutationC { ... }
}

and mutation A and B succeeded while mutation C failed, the response only included the error of C and the successful mutation data response of A and B was missing
  • Loading branch information
schroda authored Jun 3, 2024
1 parent fc2f5ff commit ff23f58
Show file tree
Hide file tree
Showing 11 changed files with 734 additions and 590 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package suwayomi.tachidesk.graphql

import com.expediagroup.graphql.server.extensions.toGraphQLError
import graphql.execution.DataFetcherResult
import mu.KotlinLogging

val logger = KotlinLogging.logger { }

inline fun <T> asDataFetcherResult(block: () -> T): DataFetcherResult<T?> {
val result =
runCatching {
block()
}

if (result.isFailure) {
logger.error(result.exceptionOrNull()) { "asDataFetcherResult: failed due to" }
return DataFetcherResult.newResult<T?>()
.error(result.exceptionOrNull()?.toGraphQLError())
.build()
}

return DataFetcherResult.newResult<T?>()
.data(result.getOrNull())
.build()
}
Loading

0 comments on commit ff23f58

Please sign in to comment.