Class AbstractGraphQLRequest

java.lang.Object
com.graphql_java_generator.client.request.AbstractGraphQLRequest
Direct Known Subclasses:
ObjectResponse

public abstract class AbstractGraphQLRequest extends Object
This class contains the description for a GraphQL request that will be sent to the server. It's an abstract class, and can not be use directly: a concrete class is generated by the plugin, when in client mode. This concrete class provides all the necessary context to this abstract class for it to work properly.
This class stores:
  • The query part, if any
  • The mutation part, if any
  • The subscription part, if any
  • The fragments, if any
Author:
etienne-sf
  • Field Details

    • packageName

      protected final String packageName
      The package name, where the GraphQL generated classes are. It's used to load the class definition, and get the GraphQL metadata coming from the GraphQL schema.
  • Constructor Details

    • AbstractGraphQLRequest

      public AbstractGraphQLRequest(org.springframework.graphql.client.GraphQlClient graphQlClient, String schema, String graphQLRequest, RequestType requestType, String fieldName, InputParameter... inputParams) throws GraphQLRequestPreparationException
      Create the instance for the given GraphQL request, for a partial request or a full request.
      Important note: this constructor SHOULD be used only by the code generated by the plugin, not by external applications. Its signature may change in the future. To prepare Partial Requests, application code SHOULD call the getXxxxGraphQLRequests methods, that are generated in the query/mutation/subscription java classes.
      Parameters:
      graphQlClient - The GraphQlClient that is responsible for the actual execution of the request
      schema - value of the springBeanSuffix plugin parameter for the searched schema. When there is only one schema, this plugin parameter is usually not set. In this case, its default value ("") is used.
      graphQLRequest - The partial GraphQL request, in text format. Writing partial request allows use to execute a query/mutation/subscription, and only define what's expected as a response for this query/mutation/subscription. You can send the parameters for this query/mutation/subscription as parameter of the java method, without dealing with bind variable in the GraphQL query. Please read the client doc page for more information, including hints and limitations.
      requestType - The information whether this queryName is actually a query, a mutation or a subscription
      fieldName - The name of the query, mutation or subscription, for instance "createHuman", in the GraphQL request "mutation {createHuman (...) { ...}}".
      inputParams - The list of input parameters for this query/mutation/subscription
      Throws:
      GraphQLRequestPreparationException
    • AbstractGraphQLRequest

      public AbstractGraphQLRequest(org.springframework.graphql.client.GraphQlClient graphQlClient, String schema, String graphQLRequest) throws GraphQLRequestPreparationException
      Creates the GraphQL request, for a full request. It will:
      • Read the query and/or the mutation
      • Read all fragment definitions
      • For all non scalar field, subfields (and so on recursively), if they are empty (that is the query doesn't define the requested fields of a non scalar field, then all its scalar fields are added)
      • Add the introspection __typename field to all scalar field list, if it doesnt't already exist. This is necessary to allow proper deserialization of interfaces and unions.
      Parameters:
      graphQlClient - The GraphQlClient that is responsible for the actual execution of the request
      schema - value of the springBeanSuffix plugin parameter for the searched schema. When there is only one schema, this plugin parameter is usually not set. In this case, its default value ("") is used.
      graphQLRequest - The GraphQL request, in text format, as defined in the GraphQL specifications, and as it can be used in GraphiQL. Please read the client doc page for more information, including hints and limitations.
      Throws:
      GraphQLRequestPreparationException
  • Method Details

    • execReactive

      public <R extends GraphQLRequestObject> reactor.core.publisher.Mono<R> execReactive(Class<R> r, Map<String,Object> params) throws GraphQLRequestExecutionException
      This method executes the current GraphQL as a query or mutation GraphQL request, and return a reactive Mono that will contain the response mapped in the relevant POJO. This method executes a partial GraphQL query, or a full GraphQL request.
      It should only be called from
      Type Parameters:
      R -
      Parameters:
      r - The type of the POJO which should be returned. As we're executing a query or a mutation, here, it must be a query or mutation class, generated from the GraphQL subscription definition in the provided schema, by the plugin
      params -
      Returns:
      A Mono the returns the result of the GraphQL request, maps on the relevant POJO
      Throws:
      GraphQLRequestExecutionException
    • exec

      public <R extends GraphQLRequestObject> R exec(Class<R> r, Map<String,Object> params) throws GraphQLRequestExecutionException
      This method executes the current GraphQL as a 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.
      Type Parameters:
      R -
      Parameters:
      r - The type of the POJO which should be returned. It must be the query or the mutation class, generated by the plugin
      params -
      Returns:
      Throws:
      GraphQLRequestExecutionException
    • execReactive

      public <R extends GraphQLRequestObject> reactor.core.publisher.Flux<R> execReactive(Map<String,Object> params, Class<R> subscriptionType) throws GraphQLRequestExecutionException
      Execution of the given subscription GraphQL request, in reactive mode. This method returns a Flux of the relevant POJO. This method executes a partial GraphQL query, or a full GraphQL request.
      Type Parameters:
      T - The type that must be returned by the subscription in the GraphQL schema, which is actually the type that will be sent in the Flux returned by this subscription.
      Parameters:
      params - the input parameters for this query. If the query has no parameters, it may be null or an empty list.
      messageType - The T class
      Returns:
      The Flux of the relevant POJO (T class), depending on the requested subscription.
      Please note that Flux may not propagate null values. So the returned POJO is embedded into an Optional, so that null values can be returned by the subscriptions. The POJO is always embedded in an Optional. This make your code homogeneous between subscriptions. And your code won't have to be changed if the GraphQL subscription definition switch from mandatory to not mandatory.
      Throws:
      GraphQLRequestExecutionException - The Flux will throw this exception when an error occurs during the request execution, typically if the request is invalid, if there is a network error, an error from the GraphQL server or if the server response can't be parsed.
      IOException
    • exec

      public <R extends GraphQLRequestObject, T> SubscriptionClient exec(Map<String,Object> params, SubscriptionCallback<T> subscriptionCallback, Class<R> subscriptionType, Class<T> messageType) throws GraphQLRequestExecutionException
      Execution of the given subscription GraphQL request, and return its response mapped in the relevant POJO. This method executes a partial GraphQL query, or a full GraphQL request.
      Note: Don't forget to free the server's resources by calling the WebSocketClient#stop() method of the returned object.
      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 is returned by the subscription in the GraphQL schema, which is actually the type that will be sent in each notification received from this subscription.
      Parameters:
      t - The type of the POJO which should be returned. It must be the query or the mutation class, generated by the plugin
      params - the input parameters for this query. 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.
      subscriptionName - The name of the subscription that should be subscribed by this method call. It will be used to check that the correct GraphQLRequest has been provided by the caller.
      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
      IOException
    • getPayload

      Returns the payload for this request. This payload can then be serialized, according to the transport protocol used.
      Parameters:
      params -
      Returns:
      Throws:
      GraphQLRequestExecutionException
    • getGraphQLObjectMapper

      public GraphQLObjectMapper getGraphQLObjectMapper()
      This method creates and configures a Jackson ObjectMapper that is ready to parse the response for this GraphQL. The main configuration is the management for the GraphQL aliases.
      Returns:
    • getGraphQLRequest

      public String getGraphQLRequest()
      Retrieve the request String that has been provided to create this instance
      Returns:
    • getGraphQLClassesPackageName

      protected abstract String getGraphQLClassesPackageName()
      This method returns the package name, where the GraphQL generated classes are. It's used to load the class definition, and get the GraphQL metadata coming from the GraphQL schema.
      Returns:
    • getQueryContext

      protected abstract QueryField getQueryContext() throws GraphQLRequestPreparationException
      Retrieved the QueryField for the query (that is the query type coming from the GraphQL schema) from the concrete class.
      Returns:
      Throws:
      GraphQLRequestPreparationException
    • getMutationContext

      protected abstract QueryField getMutationContext() throws GraphQLRequestPreparationException
      Retrieved the QueryField for the mutation (that is the mutation type coming from the GraphQL schema) from the concrete class.
      Returns:
      Throws:
      GraphQLRequestPreparationException
    • getSubscriptionClass

      protected abstract Class<? extends GraphQLRequestObject> getSubscriptionClass()
      Returns the subscription class for this schema
    • getSubscriptionContext

      protected abstract QueryField getSubscriptionContext() throws GraphQLRequestPreparationException
      Retrieved the QueryField for the subscription (that is the subscription type coming from the GraphQL schema) from the concrete class.
      Returns:
      Throws:
      GraphQLRequestPreparationException
    • getQuery

      public QueryField getQuery()
    • getMutation

      public QueryField getMutation()
    • getSubscription

      public QueryField getSubscription()
    • getFragments

      public List<Fragment> getFragments()
    • getRequestType

      public RequestType getRequestType()
    • getRequestName

      public String getRequestName()
    • logExecution

      protected static void logExecution(RequestType requestType, String queryMutationTypeName, Map<String,Object> parameters)
      Parameters:
      executionOf - A string
      parameters -