Class RequestExecutionSpringReactiveImpl

  • All Implemented Interfaces:
    RequestExecution
    Direct Known Subclasses:
    RequestExecutionGraphQLTransportWSImpl

    public class RequestExecutionSpringReactiveImpl
    extends java.lang.Object
    implements RequestExecution
    This is the default implementation for the RequestExecution This implementation has been added in version 1.12.
    It is loaded by the SpringConfiguration Spring configuration class, that is generated with the client code.
    Since:
    1.12
    Author:
    etienne-sf
    • Constructor Summary

      Constructors 
      Constructor Description
      RequestExecutionSpringReactiveImpl​(java.lang.String graphqlEndpoint, java.lang.String graphqlSubscriptionEndpoint, org.springframework.web.reactive.function.client.WebClient webClient, org.springframework.web.reactive.socket.client.WebSocketClient webSocketClient, org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction serverOAuth2AuthorizedClientExchangeFilterFunction, OAuthTokenExtractor oAuthTokenExtractor)
      This constructor may be called by Spring, once it has build a WebClient bean, or directly, in non Spring applications.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <R,​T>
      SubscriptionClient
      execute​(AbstractGraphQLRequest graphQLRequest, java.util.Map<java.lang.String,​java.lang.Object> parameters, SubscriptionCallback<T> subscriptionCallback, java.lang.Class<R> subscriptionType, java.lang.Class<T> messageType)
      Executes the given subscription GraphQL request, and returns the relevant WebSocketClient.
      <R extends GraphQLRequestObject>
      R
      execute​(AbstractGraphQLRequest graphQLRequest, java.util.Map<java.lang.String,​java.lang.Object> parameters, java.lang.Class<R> dataResponseType)
      Execution of the given query or mutation GraphQL request, and return its response mapped in the relevant POJO.
      • Methods inherited from class java.lang.Object

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

      • RequestExecutionSpringReactiveImpl

        @Autowired
        public RequestExecutionSpringReactiveImpl​(java.lang.String graphqlEndpoint,
                                                  java.lang.String graphqlSubscriptionEndpoint,
                                                  org.springframework.web.reactive.function.client.WebClient webClient,
                                                  org.springframework.web.reactive.socket.client.WebSocketClient webSocketClient,
                                                  org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction serverOAuth2AuthorizedClientExchangeFilterFunction,
                                                  OAuthTokenExtractor oAuthTokenExtractor)
        This constructor may be called by Spring, once it has build a WebClient bean, or directly, in non Spring applications.
        Parameters:
        graphqlEndpoint - A graphqlEndpoint Spring bean, of type String, must be provided, with the URL of the GraphQL endpoint, for instance https://my.serveur.com/graphql
        graphqlSubscriptionEndpoint - If the subscription is on a different endpoint than the main GraphQL endpoint, thant you can define a graphqlSubscriptionEndpoint Spring bean, of type String, with this specific URL, for instance https://my.serveur.com/graphql/subscription. For instance, Java servers suffer from a limitation which prevent to server both GET/POST HTTP verbs and WebSockets on the same URL.
        If no bean graphqlSubscriptionEndpoint Spring bean is defined, then the graphqlEndpoint URL is also used for subscriptions (which is the standard case).
        webClient - The Spring reactive WebClient that will execute the HTTP requests for GraphQL queries and mutations.
        webSocketClient - The Spring reactive WebSocketClient web socket client, that will execute HTTP requests to build the web sockets, for GraphQL subscriptions.
        This is mandatory if the application latter calls subscription. It may be null otherwise.
        serverOAuth2AuthorizedClientExchangeFilterFunction - The ServerOAuth2AuthorizedClientExchangeFilterFunction is responsible for getting OAuth token from the OAuth authorization server. It is optional, and may be provided by the App's spring config. If it is not provided, then there is no OAuth authentication on client side. If provided, then the client uses it to provide the OAuth2 authorization token, when accessing the GraphQL resource server for queries/mutations/subscriptions.
        oAuthTokenExtractor - This class is responsible for extracting the OAuth token, once the ServerOAuth2AuthorizedClientExchangeFilterFunction has done its job, and added the OAuth2 token into the request, in the Authorization header. See the OAuthTokenExtractor doc for more information.
    • Method Detail

      • execute

        public <R extends GraphQLRequestObject> R execute​(AbstractGraphQLRequest graphQLRequest,
                                                          java.util.Map<java.lang.String,​java.lang.Object> parameters,
                                                          java.lang.Class<R> dataResponseType)
                                                   throws GraphQLRequestExecutionException
        Description copied from interface: RequestExecution
        Execution of the given query or mutation GraphQL request, and return its response mapped in the relevant POJO. This method executes a partial GraphQL query, or a full GraphQL request.
        Specified by:
        execute in interface RequestExecution
        Type Parameters:
        R - The class that is generated from the query or the mutation definition in the GraphQL schema
        Parameters:
        graphQLRequest - Defines what response is expected from the server.
        parameters - the input parameters for this query. If the query has no parameters, it may be null or an empty list.
        dataResponseType - The class generated for the query or the mutation type. The data tag of the GraphQL server response will be mapped into an instance of this class.
        Returns:
        The response mapped to the code, generated from the GraphQl server. Or a wrapper for composite responses.
        Throws:
        GraphQLRequestExecutionException - When an error occurs during the request execution, typically a network error, an error from the GraphQL server or if the server response can't be parsed
      • execute

        public <R,​T> SubscriptionClient execute​(AbstractGraphQLRequest graphQLRequest,
                                                      java.util.Map<java.lang.String,​java.lang.Object> parameters,
                                                      SubscriptionCallback<T> subscriptionCallback,
                                                      java.lang.Class<R> subscriptionType,
                                                      java.lang.Class<T> messageType)
                                               throws GraphQLRequestExecutionException
        Description copied from interface: RequestExecution
        Executes the given subscription GraphQL request, and returns the relevant WebSocketClient. The given subscriptionCallback will receive the notifications that have been subscribed by this subscription. Only one Subscription may be executed at a time: it may be a partial Request (always limited to one query), or a full request that contains only one subscription.
        Note: Don't forget to free the server's resources by calling the AbstractLifeCycle.stop() method of the returned object.
        Specified by:
        execute in interface RequestExecution
        Type Parameters:
        R - The class that is generated from the subscription definition in the GraphQL schema. It contains one attribute, for each available subscription. The data tag of the GraphQL server response will be mapped into an instance of this class.
        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.
        Parameters:
        graphQLRequest - Defines what response is expected from the server.
        parameters - The input parameters for this subscription. If the query has no parameters, it may be null or an empty list.
        subscriptionCallback - The object that will be called each time a message is received, or an error on the subscription occurs. This object is provided by the application.
        subscriptionType - The R class
        messageType - The T class
        Returns:
        The Subscription client. It allows to stop the subscription, by executing its SubscriptionClient.unsubscribe() method. This will stop the incoming notification flow, and will free resources on both the client and the server.
        Throws:
        GraphQLRequestExecutionException - When an error occurs during the request execution, typically a network error, an error from the GraphQL server or if the server response can't be parsed