diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionProtocolHandler.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionProtocolHandler.kt index fcccac791..f195843d7 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionProtocolHandler.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionProtocolHandler.kt @@ -35,6 +35,7 @@ import suwayomi.tachidesk.graphql.server.subscriptions.SubscriptionOperationMess import suwayomi.tachidesk.graphql.server.subscriptions.SubscriptionOperationMessage.ServerMessages.GQL_ERROR import suwayomi.tachidesk.graphql.server.subscriptions.SubscriptionOperationMessage.ServerMessages.GQL_NEXT import suwayomi.tachidesk.graphql.server.toGraphQLContext +import suwayomi.tachidesk.server.serverConfig /** * Implementation of the `graphql-ws` protocol defined by Apollo @@ -52,9 +53,30 @@ class ApolloSubscriptionProtocolHandler( private val basicConnectionErrorMessage = SubscriptionOperationMessage(type = GQL_ERROR.type) private val acknowledgeMessage = SubscriptionOperationMessage(GQL_CONNECTION_ACK.type) + private fun getOperationName(payload: Any?): String { + val unknownOperationName = "__UNKNOWN__" + + try { + @Suppress("UNCHECKED_CAST") + return (payload as Map)["operationName"] ?: unknownOperationName + } catch (e: Exception) { + return unknownOperationName + } + } + fun handleMessage(context: WsMessageContext): Flow { val operationMessage = convertToMessageOrNull(context.message()) ?: return flowOf(basicConnectionErrorMessage) - logger.debug { "GraphQL subscription client message, sessionId=${context.sessionId} operationMessage=$operationMessage" } + logger.debug { + "GraphQL subscription client message, sessionId=${context.sessionId} type=${operationMessage.type} operationName=${ + getOperationName(operationMessage.payload) + } ${ + if (serverConfig.gqlDebugLogsEnabled.value) { + "operationMessage=$operationMessage" + } else { + "" + } + }" + } return try { when (operationMessage.type) {