我们在 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;
}
HC 是否提供类似的服务?