Class GraphQLWsHandler
java.lang.Object
io.micronaut.configuration.graphql.ws.GraphQLWsHandler
@ServerWebSocket(value="${graphql.graphql-ws.path:/graphql-ws}",
subprotocols="graphql-transport-ws")
@Requires(property="graphql.graphql-ws.enabled",
value="true",
defaultValue="false")
public class GraphQLWsHandler
extends Object
WebSocket request handler for the graphql-ws protocol. Supports the 'graphql-transport-ws' WebSocket subprotocol.
- Since:
- 4.0
- Author:
- Jeremy Grelle
-
Constructor Summary
ConstructorDescriptionGraphQLWsHandler
(io.micronaut.scheduling.ScheduledExecutorTaskScheduler scheduler, GraphQLInvocation graphQLInvocation, GraphQLWsConfiguration configuration) Constructor for the graphql-ws WebSocket handler. -
Method Summary
Modifier and TypeMethodDescriptionvoid
onClose
(io.micronaut.websocket.WebSocketSession session, io.micronaut.websocket.CloseReason closeReason) Called when the websocket is closed.void
Called when there is an error with the websocket.org.reactivestreams.Publisher<Message>
Called on every message received from the client.void
onOpen
(io.micronaut.websocket.WebSocketSession session, io.micronaut.http.HttpRequest request) Called when the connection is opened.
-
Constructor Details
-
GraphQLWsHandler
public GraphQLWsHandler(io.micronaut.scheduling.ScheduledExecutorTaskScheduler scheduler, GraphQLInvocation graphQLInvocation, GraphQLWsConfiguration configuration) Constructor for the graphql-ws WebSocket handler.- Parameters:
scheduler
- The task scheduler for handling connection initialisation timeouts.graphQLInvocation
- The graphql invocation helper for executing GraphQL operations.configuration
- The configuration of the graphql-ws support.
-
-
Method Details
-
onOpen
@OnOpen public void onOpen(io.micronaut.websocket.WebSocketSession session, io.micronaut.http.HttpRequest request) Called when the connection is opened. We store the original request, since it might be needed for the GraphQLInvocation.- Parameters:
session
- WebSocketSessionrequest
- HttpRequest
-
onMessage
@OnMessage public org.reactivestreams.Publisher<Message> onMessage(Message message, io.micronaut.websocket.WebSocketSession session) Called on every message received from the client.- Parameters:
message
- Message received from a clientsession
- WebSocketSession- Returns:
Publisher<Message>
-
onClose
@OnClose public void onClose(io.micronaut.websocket.WebSocketSession session, io.micronaut.websocket.CloseReason closeReason) Called when the websocket is closed.- Parameters:
session
- TheWebSocketSession
being closed.closeReason
- TheCloseReason
describing why the socket has been closed.
-
onError
Called when there is an error with the websocket. If a JSON decoding error is detected, the socket will be closed with a4400
error as defined by the graphql-ws spec.- Parameters:
session
- TheWebSocketSession
where an error occurred.t
-Throwable
, the cause of the error
-