From 0c555e88d379b14161727237a09f4840a46bf1a2 Mon Sep 17 00:00:00 2001 From: Valter Martinek Date: Fri, 11 Nov 2022 11:31:38 +0100 Subject: [PATCH] Update graphql-playground endpoint --- .../kotlin/suwayomi/tachidesk/graphql/GraphQL.kt | 10 ++++------ .../graphql/controller/GraphQLController.kt | 16 ++++++++++++++++ .../{graphql.html => graphql-playground.html} | 6 ++++-- 3 files changed, 24 insertions(+), 8 deletions(-) rename server/src/main/resources/{graphql.html => graphql-playground.html} (90%) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/GraphQL.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/GraphQL.kt index 8bc2edab..82093452 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/GraphQL.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/GraphQL.kt @@ -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) } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/controller/GraphQLController.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/controller/GraphQLController.kt index 711e9cb5..615db95c 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/controller/GraphQLController.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/controller/GraphQLController.kt @@ -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(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") + } } diff --git a/server/src/main/resources/graphql.html b/server/src/main/resources/graphql-playground.html similarity index 90% rename from server/src/main/resources/graphql.html rename to server/src/main/resources/graphql-playground.html index 23825856..894ff66f 100644 --- a/server/src/main/resources/graphql.html +++ b/server/src/main/resources/graphql-playground.html @@ -50,9 +50,11 @@ - \ No newline at end of file +