C# 热巧克力:如何访问;“初始连接”;有效载荷
我们正在连接_init期间发送额外的有效负载(阿波罗的connectionParams in) 我在官方来源中找不到关于如何提取此类信息的任何信息,也找不到关于任何消息中间件/处理程序的任何信息 并发解决方案graphql dotnet允许我像这样实现IOperationMessageListenerC# 热巧克力:如何访问;“初始连接”;有效载荷,c#,asp.net-core,.net-core,hotchocolate,C#,Asp.net Core,.net Core,Hotchocolate,我们正在连接_init期间发送额外的有效负载(阿波罗的connectionParams in) 我在官方来源中找不到关于如何提取此类信息的任何信息,也找不到关于任何消息中间件/处理程序的任何信息 并发解决方案graphql dotnet允许我像这样实现IOperationMessageListener public class SusbcriptionInitListener: IOperationMessageListener { public Task BeforeHandleAsy
public class SusbcriptionInitListener: IOperationMessageListener
{
public Task BeforeHandleAsync(MessageHandlingContext context) => Task.CompletedTask;
// This method will be triggered with every incoming message
public async Task HandleAsync(MessageHandlingContext context)
{
var message = context.Message;
// I can then filter for specific message type and do something with the raw playload
if (message.Type == MessageType.GQL_CONNECTION_INIT)
{
string myInformation = message.Payload.GetValue("MyInfomration").ToString();
DoSomethingWithMyInformation(myInformation);
}
}
public Task AfterHandleAsync(MessageHandlingContext context) => Task.CompletedTask;
}
HC是否提供类似的功能?您需要的是
ISocketSessionInterceptor
服务
AddGraphQLServer()
... 你的配置
.AddSocketSessionInterceptor();
公共接口ISocketSessionInterceptor
{
ValueTaskOnConnectAsync(
等电位连接,
InitializeConnectionMessage消息,
取消令牌取消令牌);
ValueTaskOnRequestAsync(
等电位连接,
IQueryRequestBuilder请求生成器,
取消令牌取消令牌);
ValueTaskOnCloseAsync(
等电位连接,
取消令牌取消令牌);
}
您可以通过覆盖OnConnectAsync
来访问连接请求负载
InitializeConnectionMessage
包含一个保存有效负载的Payload
属性