diff --git a/src/GraphQL.AspNetCore3/WebSockets/GraphQLWs/SubscriptionServer.cs b/src/GraphQL.AspNetCore3/WebSockets/GraphQLWs/SubscriptionServer.cs index 9b57782..47e6924 100644 --- a/src/GraphQL.AspNetCore3/WebSockets/GraphQLWs/SubscriptionServer.cs +++ b/src/GraphQL.AspNetCore3/WebSockets/GraphQLWs/SubscriptionServer.cs @@ -115,7 +115,9 @@ public override async Task OnMessageReceivedAsync(OperationMessage message) /// Executes when a ping message is received. /// protected virtual Task OnPingAsync(OperationMessage message) - => Connection.SendMessageAsync(_pongMessage); + => message.Payload == null + ? Connection.SendMessageAsync(_pongMessage) + : Connection.SendMessageAsync(new OperationMessage { Type = MessageType.Pong, Payload = message.Payload }); /// /// Executes when a pong message is received. diff --git a/src/Tests/WebSockets/NewSubscriptionServerTests.cs b/src/Tests/WebSockets/NewSubscriptionServerTests.cs index d703f31..86d749b 100644 --- a/src/Tests/WebSockets/NewSubscriptionServerTests.cs +++ b/src/Tests/WebSockets/NewSubscriptionServerTests.cs @@ -94,11 +94,15 @@ public async Task Message_ThrowsWhenNotInitialized(string? messageType) } [Theory] - [InlineData(false)] - [InlineData(true)] - public async Task Message_Ping(bool initialized) + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task Message_Ping(bool initialized, bool withPayload) { var message = new OperationMessage { Type = "ping" }; + if (withPayload) + message.Payload = new { id = Guid.NewGuid().ToString("N") }; _mockServer.Protected().Setup("OnPingAsync", message) .Returns(Task.CompletedTask).Verifiable(); if (initialized) {