Class GraphQLHandler

  • All Implemented Interfaces:

    
    public final class GraphQLHandler
    
                        

    Serves GraphQL subscriptions over the graphql-transport-ws protocol (https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md).

    The message types come from graphql-kotlin, but they are annotated for Jackson 3 and fastjson2, so incoming frames are dispatched on the type field by hand rather than deserialized into the sealed GraphQLSubscriptionMessage. That keeps the plugin working with whatever JsonMapper the application has configured.

    Note on subprotocol negotiation: Javalin exposes no API for it, and the Jetty handshake underneath echoes back whichever subprotocol the client requested first, without checking it. A graphql-transport-ws client therefore connects correctly, but a client asking for something this handler does not speak — the legacy graphql-ws subprotocol, say — is told yes and then receives messages it cannot understand. Rejecting those needs a Javalin change.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Unit onMessage(WsMessageContext ctx)
      final Unit onClose(WsCloseContext ctx) Cancels everything still running for a connection that went away.
      final Unit shutdown() Cancels every subscription still running and releases the scope.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • onClose

         final Unit onClose(WsCloseContext ctx)

        Cancels everything still running for a connection that went away.

      • shutdown

         final Unit shutdown()

        Cancels every subscription still running and releases the scope. Called once, when the server is stopping. The scope is not reusable afterwards, which is fine: a Javalin instance cannot be restarted.