Class GraphQLReactiveWebSocketHandler
java.lang.Object
com.graphql_java_generator.client.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.
- Author:
- etienne-sf
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GraphQLReactiveWebSocketHandler.MessageType
-
Constructor Summary
Constructors Constructor Description GraphQLReactiveWebSocketHandler(GraphQLObjectMapper objectMapper)
-
Method Summary
Modifier and Type Method Description void
checkInitializationError()
Returns the error that occurs during the initialization phase, that is while sending the connection_init<R extends GraphQLRequestObject>
RexecuteQueryOrMutation(java.util.Map<java.lang.String,java.lang.Object> request, java.lang.Class<R> requestType)
This method executes a query or a mutation over this web socket, as described in the graphql-transport-ws protocol.<R, T> java.lang.String
executeSubscription(java.util.Map<java.lang.String,java.lang.Object> request, java.lang.String subscriptionName, SubscriptionCallback<T> subscriptionCallback, java.lang.Class<R> subscriptionType, java.lang.Class<T> messsageType)
Execution of a subscription, from the given request.org.springframework.web.reactive.socket.WebSocketSession
getSession()
java.util.List<java.lang.String>
getSubProtocols()
reactor.core.publisher.Mono<java.lang.Void>
handle(org.springframework.web.reactive.socket.WebSocketSession sessionParam)
void
onComplete()
void
onError(java.lang.Throwable t)
void
onNext(org.springframework.web.reactive.socket.WebSocketMessage message)
The callback that will receive the messages from the web socket.void
unsubscribe(java.lang.String uniqueIdOperation)
-
Constructor Details
-
Method Details
-
executeSubscription
public <R, T> java.lang.String executeSubscription(java.util.Map<java.lang.String,java.lang.Object> request, java.lang.String subscriptionName, SubscriptionCallback<T> subscriptionCallback, java.lang.Class<R> subscriptionType, java.lang.Class<T> messsageType) throws GraphQLRequestExecutionExceptionExecution of a subscription, from the given request.- Type Parameters:
R
-T
-- Parameters:
request
-subscriptionName
-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
-
executeQueryOrMutation
public <R extends GraphQLRequestObject> R executeQueryOrMutation(java.util.Map<java.lang.String,java.lang.Object> request, java.lang.Class<R> requestType) throws GraphQLRequestExecutionExceptionThis method executes a query or a mutation over this web socket, as described in the graphql-transport-ws protocol.- Type Parameters:
R
-- Parameters:
request
- The json map that contains the request to executerequestType
- The java type that matches the query or mutation type defined in the GraphQL schema.- Returns:
- Throws:
GraphQLRequestExecutionException
-
unsubscribe
public void unsubscribe(java.lang.String uniqueIdOperation) throws GraphQLRequestExecutionException- Throws:
GraphQLRequestExecutionException
-
checkInitializationError
Returns the error that occurs during the initialization phase, that is while sending the connection_init- Throws:
GraphQLRequestExecutionException
- When an error occurs before the Web Socket and the subscription are properly initialized.
-
handle
public reactor.core.publisher.Mono<java.lang.Void> handle(org.springframework.web.reactive.socket.WebSocketSession sessionParam)- Specified by:
handle
in interfaceorg.springframework.web.reactive.socket.WebSocketHandler
-
onNext
public void onNext(org.springframework.web.reactive.socket.WebSocketMessage message)The callback that will receive the messages from the web socket. It will map these JSON messages to the relevant java class, and call the application callback with this java objects. This message can be any valid message, according to the graphql-transport-ws protocol- Parameters:
message
- The received JSON message
-
onError
public void onError(java.lang.Throwable t) -
onComplete
public void onComplete() -
getSubProtocols
public java.util.List<java.lang.String> getSubProtocols()- Specified by:
getSubProtocols
in interfaceorg.springframework.web.reactive.socket.WebSocketHandler
-
getSession
public org.springframework.web.reactive.socket.WebSocketSession getSession()
-