Class AbstractGraphQLRequest

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

public abstract class AbstractGraphQLRequest
extends java.lang.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 Summary

    Fields 
    Modifier and Type Field Description
    protected java.lang.String packageName
    The package name, where the GraphQL generated classes are.
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractGraphQLRequest​(java.lang.String graphQLRequest)
    Creates the GraphQL request, for a full request.
    AbstractGraphQLRequest​(java.lang.String graphQLRequest, RequestType requestType, java.lang.String fieldName, InputParameter... inputParams)
    Create the instance, from the GraphQL request, for a partial request.
    Important note: this constructor SHOULD NOT be called by external application.
  • Method Summary

    Modifier and Type Method Description
    java.lang.String buildRequest​(java.util.Map<java.lang.String,​java.lang.Object> params)  
    <T extends GraphQLRequestObject>
    T
    exec​(java.lang.Class<T> t, java.util.Map<java.lang.String,​java.lang.Object> params)
    This method executes the current GraphQL as a query or mutation GraphQL request, and return its response mapped in the relevant POJO.
    <R,​ T> SubscriptionClient exec​(java.util.Map<java.lang.String,​java.lang.Object> params, SubscriptionCallback<T> subscriptionCallback, java.lang.Class<R> subscriptionType, java.lang.Class<T> messageType)
    Execution of the given subscription GraphQL request, and return its response mapped in the relevant POJO.
    java.util.List<Fragment> getFragments()  
    protected abstract java.lang.String getGraphQLClassesPackageName()
    This method returns the package name, where the GraphQL generated classes are.
    GraphQLObjectMapper getGraphQLObjectMapper()
    This method creates and configures a Jackson ObjectMapper that is ready to parse the response for this GraphQL.
    java.lang.String getGraphQLRequest()
    Retrieve the request String that has been provided to create this instance
    GraphQLConfiguration getInstanceConfiguration()
    This gets the configuration for this instance.
    QueryField getMutation()  
    protected abstract QueryField getMutationContext()
    Retrieved the QueryField for the mutation (that is the mutation type coming from the GraphQL schema) from the concrete class.
    QueryField getQuery()  
    protected abstract QueryField getQueryContext()
    Retrieved the QueryField for the query (that is the query type coming from the GraphQL schema) from the concrete class.
    java.lang.String getRequestName()  
    RequestType getRequestType()  
    static GraphQLConfiguration getStaticConfiguration()
    This gets the default configuration, that will apply if no local configuration has been defined for this instance.
    QueryField getSubscription()  
    protected abstract QueryField getSubscriptionContext()
    Retrieved the QueryField for the subscription (that is the subscription type coming from the GraphQL schema) from the concrete class.
    void setInstanceConfiguration​(GraphQLConfiguration instanceConfiguration)
    This sets the configuration for this instance.
    static void setStaticConfiguration​(GraphQLConfiguration staticConfiguration)
    This sets the default configuration, that will apply if no local configuration has been defined for this instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • packageName

      protected final java.lang.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​(java.lang.String graphQLRequest, RequestType requestType, java.lang.String fieldName, InputParameter... inputParams) throws GraphQLRequestPreparationException
      Create the instance, from the GraphQL request, for a partial request.
      Important note: this constructor SHOULD NOT be called by external application. 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:
      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​(java.lang.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:
      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

    • exec

      public <T extends GraphQLRequestObject> T exec​(java.lang.Class<T> t, java.util.Map<java.lang.String,​java.lang.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.
      Note: Don't forget to free the server's resources by calling the AbstractLifeCycle.stop() method of the returned object.
      Type Parameters:
      T -
      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 -
      Returns:
      Throws:
      GraphQLRequestExecutionException
    • exec

      public <R,​ T> SubscriptionClient exec​(java.util.Map<java.lang.String,​java.lang.Object> params, SubscriptionCallback<T> subscriptionCallback, java.lang.Class<R> subscriptionType, java.lang.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 AbstractLifeCycle.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
      java.io.IOException
    • buildRequest

      public java.lang.String buildRequest​(java.util.Map<java.lang.String,​java.lang.Object> params) throws GraphQLRequestExecutionException
      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 java.lang.String getGraphQLRequest()
      Retrieve the request String that has been provided to create this instance
      Returns:
    • getGraphQLClassesPackageName

      protected abstract java.lang.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
    • 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 java.util.List<Fragment> getFragments()
    • getRequestType

      public RequestType getRequestType()
    • getRequestName

      public java.lang.String getRequestName()
    • getStaticConfiguration

      public static GraphQLConfiguration getStaticConfiguration()
      This gets the default configuration, that will apply if no local configuration has been defined for this instance.
      Returns:
      the staticConfiguration
    • setStaticConfiguration

      public static void setStaticConfiguration​(GraphQLConfiguration staticConfiguration)
      This sets the default configuration, that will apply if no local configuration has been defined for this instance.
      Parameters:
      staticConfiguration - the staticConfiguration to set
    • getInstanceConfiguration

      public GraphQLConfiguration getInstanceConfiguration()
      This gets the configuration for this instance. This configuration overrides the getStaticConfiguration(), if defined.
      Returns:
      the instanceConfiguration
    • setInstanceConfiguration

      public void setInstanceConfiguration​(GraphQLConfiguration instanceConfiguration)
      This sets the configuration for this instance. This configuration overrides the getStaticConfiguration(), if defined.
      Parameters:
      instanceConfiguration - the instanceConfiguration to set