mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 10:54:38 -05:00
Update graphql-playground endpoint
This commit is contained in:
@@ -7,16 +7,14 @@
|
||||
|
||||
package suwayomi.tachidesk.graphql
|
||||
|
||||
import io.javalin.apibuilder.ApiBuilder.get
|
||||
import io.javalin.apibuilder.ApiBuilder.post
|
||||
import io.javalin.apibuilder.ApiBuilder.*
|
||||
import suwayomi.tachidesk.graphql.controller.GraphQLController
|
||||
|
||||
object GraphQL {
|
||||
fun defineEndpoints() {
|
||||
post("graphql", GraphQLController.execute)
|
||||
get("graphql") { ctx ->
|
||||
val html = javaClass.getResource("/graphql.html")?.readText()
|
||||
ctx.html(html ?: "Could not load playground")
|
||||
}
|
||||
|
||||
// graphql playground
|
||||
get("graphql", GraphQLController::playground)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package suwayomi.tachidesk.graphql.controller
|
||||
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import io.javalin.http.Context
|
||||
import io.javalin.http.HttpCode
|
||||
import suwayomi.tachidesk.graphql.impl.getGraphQLServer
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
@@ -38,4 +39,19 @@ object GraphQLController {
|
||||
json<Any>(HttpCode.OK)
|
||||
}
|
||||
)
|
||||
|
||||
fun playground(ctx: Context) {
|
||||
val playgroundHtml = javaClass.getResource("/graphql-playground.html")
|
||||
|
||||
val body = playgroundHtml.openStream().bufferedReader().use { reader ->
|
||||
val graphQLEndpoint = "graphql"
|
||||
val subscriptionsEndpoint = "graphql"
|
||||
|
||||
reader.readText()
|
||||
.replace("\${graphQLEndpoint}", graphQLEndpoint)
|
||||
.replace("\${subscriptionsEndpoint}", subscriptionsEndpoint)
|
||||
}
|
||||
|
||||
ctx.html(body ?: "Could not load playground")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user