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 70075ba
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,26 @@ class ApolloSubscriptionProtocolHandler(
private val basicConnectionErrorMessage = SubscriptionOperationMessage(type = GQL_ERROR.type)
private val acknowledgeMessage = SubscriptionOperationMessage(GQL_CONNECTION_ACK.type)

private fun getOperationName(payload: Any?): String {
try {
@Suppress("UNCHECKED_CAST")
return (payload as Map<String, String>)["operationName"]!!
} catch (e: Exception) {
return "__UNKNOWN__"
}
}

fun handleMessage(context: WsMessageContext): Flow<SubscriptionOperationMessage> {
val operationMessage = convertToMessageOrNull(context.message()) ?: return flowOf(basicConnectionErrorMessage)
logger.debug {
"GraphQL subscription client message, sessionId=${context.sessionId} ${
if (serverConfig.gqlDebugLogsEnabled.value) {
"operationMessage=$operationMessage"
} else {
""
}
"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 70075ba

Please sign in to comment.