Class GraphQLSubscriptionHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.websocketx.WebSocketFrame>
org.mockserver.mock.action.http.GraphQLSubscriptionHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

public class GraphQLSubscriptionHandler extends io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.websocketx.WebSocketFrame>
Handles the graphql-transport-ws protocol over an already-established WebSocket connection.

Installed after the WebSocket handshake when the negotiated subprotocol is graphql-transport-ws or the legacy graphql-ws.

Protocol messages handled:

  • connection_init - replies connection_ack
  • ping - replies pong
  • subscribe - AST-matches the query against the configured subscription expectation; on match pushes a scripted sequence of next messages then complete; on no match sends error
  • complete (client) - cancels that subscription's pending messages

Inbound breakpoints (A1e): when an INBOUND_STREAM breakpoint matcher is registered and inbound stream ID is configured, incoming WebSocket frames are parked in the StreamFrameBreakpointRegistry before protocol dispatch. The frame text is copied to byte[] (UTF-8) at park time and the original TextWebSocketFrame is released immediately. On resume, the text is reconstructed from the captured/modified bytes. Backpressure is applied via autoRead=false while a frame is parked.

  • Constructor Details

    • GraphQLSubscriptionHandler

      public GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker)
      Original constructor — no inbound breakpoint support (backward compatible).
      Parameters:
      expectedSubscriptionQuery - a GraphQLBody describing the subscription query to match
      subscriptionPayloads - the sequence of payloads to push as next messages
      frameSender - callback for sending text frames with optional delays
      handshaker - the WebSocket handshaker for closing the connection
    • GraphQLSubscriptionHandler

      public GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker, Configuration configuration, String inboundStreamId, WebSocketClientRegistry webSocketClientRegistry)
      Deprecated.
      use the constructor that accepts inboundBreakpointClientId and inboundBreakpointId
      Constructor with inbound breakpoint support (performs its own findMatch for backward compatibility).
    • GraphQLSubscriptionHandler

      public GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker, Configuration configuration, String inboundStreamId, WebSocketClientRegistry webSocketClientRegistry, String inboundBreakpointClientId, String inboundBreakpointId)
      Constructor with inbound breakpoint support and pre-resolved breakpoint identity.
      Parameters:
      expectedSubscriptionQuery - a GraphQLBody describing the subscription query to match
      subscriptionPayloads - the sequence of payloads to push as next messages
      frameSender - callback for sending text frames with optional delays
      handshaker - the WebSocket handshaker for closing the connection
      configuration - the active server configuration (null to disable inbound breakpoints)
      inboundStreamId - the stream ID for inbound breakpoints (null to disable)
      webSocketClientRegistry - the per-server WS registry for callback dispatch (null to disable WS dispatch)
      inboundBreakpointClientId - the matched inbound breakpoint's owning clientId (from outer caller)
      inboundBreakpointId - the matched inbound breakpoint's id (from outer caller)
    • GraphQLSubscriptionHandler

      public GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker, Configuration configuration, String inboundStreamId, WebSocketClientRegistry webSocketClientRegistry, String inboundBreakpointClientId, String inboundBreakpointId, String negotiatedSubprotocol)
      Constructor taking the subprotocol actually negotiated during the handshake.
      Parameters:
      negotiatedSubprotocol - the negotiated WebSocket subprotocol; when this is the legacy graphql-ws (subscriptions-transport-ws) protocol the handler speaks that protocol's vocabulary (start/stop/data) instead of the graphql-transport-ws vocabulary
  • Method Details

    • channelRead0

      protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.WebSocketFrame frame)
      Specified by:
      channelRead0 in class io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.websocketx.WebSocketFrame>
    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
    • channelInactive

      public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelInactive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • isGraphQLWebSocketProtocol

      public static boolean isGraphQLWebSocketProtocol(String subprotocol)
      Check whether the given subprotocol string indicates a graphql-transport-ws or legacy graphql-ws protocol.