Table of Contents

Interface ISocketSessionInterceptor

Namespace
HotChocolate.AspNetCore
Assembly
HotChocolate.AspNetCore.dll

The socket interceptor allows to customize the GraphQL over Websocket behavior.

public interface ISocketSessionInterceptor

Methods

OnCloseAsync(ISocketSession, CancellationToken)

Invoked when the connection is closed.

ValueTask OnCloseAsync(ISocketSession session, CancellationToken cancellationToken = default)

Parameters

session ISocketSession

The socket session.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

OnCompleteAsync(ISocketSession, string, CancellationToken)

Invoked when the execution of a GraphQL request is completed. This interception method is guaranteed to be invoked even if the operation fails or the connection is closed.

The cancellation token might be cancelled if the connection is closed.

ValueTask OnCompleteAsync(ISocketSession session, string operationSessionId, CancellationToken cancellationToken = default)

Parameters

session ISocketSession

The socket session.

operationSessionId string

The user-provided unique operation session id.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

OnConnectAsync(ISocketSession, IOperationMessagePayload, CancellationToken)

Invoked when the socket connection initialization message is received.

ValueTask<ConnectionStatus> OnConnectAsync(ISocketSession session, IOperationMessagePayload connectionInitMessage, CancellationToken cancellationToken = default)

Parameters

session ISocketSession

The socket session.

connectionInitMessage IOperationMessagePayload

The connection init message that was received.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<ConnectionStatus>

Returns the connection status that specifies if the socket connection shall be accepted or if it shall be refused.

OnPingAsync(ISocketSession, IOperationMessagePayload, CancellationToken)

Invoked when a ping message is received and allows to produce the payload for the pong message.

ValueTask<IReadOnlyDictionary<string, object?>?> OnPingAsync(ISocketSession session, IOperationMessagePayload pingMessage, CancellationToken cancellationToken = default)

Parameters

session ISocketSession

The socket session.

pingMessage IOperationMessagePayload

The ping message.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<IReadOnlyDictionary<string, object>>

Returns the Pong-message payload.

OnPongAsync(ISocketSession, IOperationMessagePayload, CancellationToken)

Invoked when a pong message is received.

ValueTask OnPongAsync(ISocketSession session, IOperationMessagePayload pongMessage, CancellationToken cancellationToken = default)

Parameters

session ISocketSession

The socket session.

pongMessage IOperationMessagePayload

The pong message.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

OnRequestAsync(ISocketSession, string, IQueryRequestBuilder, CancellationToken)

Invoked when a GraphQL request is registered with the socket session.

ValueTask OnRequestAsync(ISocketSession session, string operationSessionId, IQueryRequestBuilder requestBuilder, CancellationToken cancellationToken = default)

Parameters

session ISocketSession

The socket session.

operationSessionId string

The user-provided unique operation session id.

requestBuilder IQueryRequestBuilder

The GraphQL request builder.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask

OnResultAsync(ISocketSession, string, IQueryResult, CancellationToken)

Invoked before the result is serialized and send to the client. This interception method allows to amend the result object.

ValueTask<IQueryResult> OnResultAsync(ISocketSession session, string operationSessionId, IQueryResult result, CancellationToken cancellationToken = default)

Parameters

session ISocketSession

The socket session.

operationSessionId string

The user-provided unique operation session id.

result IQueryResult

The result produced by executing the GraphQL request.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<IQueryResult>

Returns the result that shall be send to the client.