小编Luk*_*zka的帖子

HotChocolate:如何访问“connection_init”有效负载

我们在connection_init期间发送额外的有效负载( Apollo的https://github.com/apollographql/subscriptions-transport-ws中的connectionParams )。

我无法在官方来源中找到有关如何提取此类信息的任何信息,也无法找到有关任何消息中间件/处理程序的任何类型的信息。

并发解决方案 graphql-dotnet 允许我像这样实现 IOperationMessageListener

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;
}
Run Code Online (Sandbox Code Playgroud)

HC有类似的东西吗?

c# .net-core asp.net-core hotchocolate

5
推荐指数
1
解决办法
684
查看次数

标签 统计

.net-core ×1

asp.net-core ×1

c# ×1

hotchocolate ×1