Skip to content

Commit

Permalink
Always log message type and operation name
Browse files Browse the repository at this point in the history
  • Loading branch information
schroda committed Oct 4, 2023
1 parent 5efd271 commit dedd707
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,23 @@ 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<String, String>)["operationName"] ?: unknownOperationName
} catch (e: Exception) {
return unknownOperationName
}
}

fun handleMessage(context: WsMessageContext): Flow<SubscriptionOperationMessage> {
val operationMessage = convertToMessageOrNull(context.message()) ?: return flowOf(basicConnectionErrorMessage)
logger.debug {
"GraphQL subscription client message, sessionId=${context.sessionId} ${
"GraphQL subscription client message, sessionId=${context.sessionId} type=${operationMessage.type} operationName=${
getOperationName(operationMessage.payload)
} ${
if (serverConfig.gqlDebugLogsEnabled.value) {
"operationMessage=$operationMessage"
} else {
Expand Down

0 comments on commit dedd707

Please sign in to comment.