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 sub-protocol.
Since:
4.0
Author:
Jeremy Grelle
  • Constructor Summary

    Constructors
    Constructor
    Description
    GraphQLWsHandler(io.micronaut.scheduling.ScheduledExecutorTaskScheduler scheduler, GraphQLInvocation graphQLInvocation, GraphQLWsConfiguration configuration)
    Constructor for the graphql-ws WebSocket handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onClose(io.micronaut.websocket.WebSocketSession session, io.micronaut.websocket.CloseReason closeReason)
    Called when the websocket is closed.
    void
    onError(io.micronaut.websocket.WebSocketSession session, Throwable t)
    Called when there is an error with the websocket.
    org.reactivestreams.Publisher<Message>
    onMessage(Message message, io.micronaut.websocket.WebSocketSession session)
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 - WebSocketSession
      request - 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 client
      session - 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 - The WebSocketSession being closed.
      closeReason - The CloseReason describing why the socket has been closed.
    • onError

      @OnError public void onError(io.micronaut.websocket.WebSocketSession session, Throwable t)
      Called when there is an error with the websocket. If a JSON decoding error is detected, the socket will be closed with a 4400 error as defined by the graphql-ws spec.
      Parameters:
      session - The WebSocketSession where an error occurred.
      t - Throwable, the cause of the error