我们在connection_init期间发送额外的有效载荷(用于阿波罗的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有没有提供类似的东西?
发布于 2021-01-18 01:11:48
您要查找的是ISocketSessionInterceptor
services
AddGraphQLServer()
... Your Config
.AddSocketSessionInterceptor<AuthenticationSocketInterceptor>();public interface ISocketSessionInterceptor
{
ValueTask<ConnectionStatus> OnConnectAsync(
ISocketConnection connection,
InitializeConnectionMessage message,
CancellationToken cancellationToken);
ValueTask OnRequestAsync(
ISocketConnection connection,
IQueryRequestBuilder requestBuilder,
CancellationToken cancellationToken);
ValueTask OnCloseAsync(
ISocketConnection connection,
CancellationToken cancellationToken);
}您可以通过覆盖OnConnectAsync来访问连接请求负载。
InitializeConnectionMessage包含一个保存有效负载的Payload属性
https://stackoverflow.com/questions/65703280
复制相似问题