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
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Callback interface for sending text frames to the client, with optional delay support.

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Constructor Summary

    Constructors
    Constructor
    Description
    GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.WebSocketFrame frame)
     
    void
    exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
     
    static boolean
    Check whether the given subprotocol string indicates a graphql-transport-ws or legacy graphql-ws protocol.

    Methods inherited from class io.netty.channel.SimpleChannelInboundHandler

    acceptInboundMessage, channelRead

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Constructor Details

    • GraphQLSubscriptionHandler

      public GraphQLSubscriptionHandler(GraphQLBody expectedSubscriptionQuery, List<WebSocketMessage> subscriptionPayloads, GraphQLSubscriptionHandler.FrameSender frameSender, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker handshaker)
      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
  • 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
    • isGraphQLWebSocketProtocol

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