Class GraphQLReactiveWebSocketHandler

  • Type Parameters:
    R - The class that is generated from the subscription definition in the GraphQL schema. It contains one attribute, for each available subscription. In the incoming messages, the data JSON field of the GraphQL server response is of this type. So it is needed to decode the received JSON.
    T - The type that must be returned by the query or mutation: it's the class that maps to the GraphQL type returned by this subscription. In other words, it's the java type that matches the field in the subscription GraphQL type, for this subscribed subscription.
    All Implemented Interfaces:
    org.springframework.web.reactive.socket.WebSocketHandler

    public class GraphQLReactiveWebSocketHandler
    extends java.lang.Object
    implements org.springframework.web.reactive.socket.WebSocketHandler
    This class implements the Web Socket, as needed by the Spring Web Socket implementation. It applies the graphql-transport-ws) protocol for all requests (queries, mutations and subscriptions). That is: all requests are executed within the same web socket.
    Author:
    etienne-sf
    • Constructor Summary

      Constructors 
      Constructor Description
      GraphQLReactiveWebSocketHandler​(java.lang.String graphqlEndpoint, java.lang.String graphqlSubscriptionEndpoint, org.springframework.web.reactive.socket.client.WebSocketClient webSocketClient, org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction serverOAuth2AuthorizedClientExchangeFilterFunction, OAuthTokenExtractor oAuthTokenExtractor)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <R extends GraphQLRequestObject>
      R
      executeQueryOrMutation​(AbstractGraphQLRequest graphQLRequest, java.util.Map<java.lang.String,​java.lang.Object> parameters, java.lang.Class<R> dataResponseType)
      Execution of a query or a mutation, from the given request and parameters, onto this Web Socket.
      <R,​T>
      SubscriptionClient
      executeSubscription​(AbstractGraphQLRequest request, java.util.Map<java.lang.String,​java.lang.Object> parameters, SubscriptionCallback<T> subscriptionCallback, java.lang.Class<R> subscriptionType, java.lang.Class<T> messsageType)
      Execution of a subscription, from the given request and parameters, onto this Web Socket.
      java.util.List<java.lang.String> getSubProtocols()  
      java.net.URI getWebSocketURI()
      Retrieves the URI for the Web Socket, based on the GraphQL endpoint that has been given to the Constructor
      reactor.core.publisher.Mono<java.lang.Void> handle​(org.springframework.web.reactive.socket.WebSocketSession session)
      Managing of a new Web Socket session.
      • Methods inherited from class java.lang.Object

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

      • GraphQLReactiveWebSocketHandler

        public GraphQLReactiveWebSocketHandler​(java.lang.String graphqlEndpoint,
                                               java.lang.String graphqlSubscriptionEndpoint,
                                               org.springframework.web.reactive.socket.client.WebSocketClient webSocketClient,
                                               org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction serverOAuth2AuthorizedClientExchangeFilterFunction,
                                               OAuthTokenExtractor oAuthTokenExtractor)
    • Method Detail

      • handle

        public reactor.core.publisher.Mono<java.lang.Void> handle​(org.springframework.web.reactive.socket.WebSocketSession session)
        Managing of a new Web Socket session. This method is the only method of this class. All the work is delegated.
        Specified by:
        handle in interface org.springframework.web.reactive.socket.WebSocketHandler
      • executeSubscription

        public <R,​T> SubscriptionClient executeSubscription​(AbstractGraphQLRequest request,
                                                                  java.util.Map<java.lang.String,​java.lang.Object> parameters,
                                                                  SubscriptionCallback<T> subscriptionCallback,
                                                                  java.lang.Class<R> subscriptionType,
                                                                  java.lang.Class<T> messsageType)
                                                           throws GraphQLRequestExecutionException
        Execution of a subscription, from the given request and parameters, onto this Web Socket.
        Type Parameters:
        R -
        T -
        Parameters:
        request -
        parameters - The parameter's map, that contain the parameters name and value
        subscriptionCallback -
        subscriptionType -
        messsageType -
        Returns:
        The unique Id Operation that is returned by the server for this subscription, as specified by the graphql-transport-ws protocol
        Throws:
        GraphQLRequestExecutionException
      • getSubProtocols

        public java.util.List<java.lang.String> getSubProtocols()
        Specified by:
        getSubProtocols in interface org.springframework.web.reactive.socket.WebSocketHandler