Class 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 Detail

      • 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 Detail

      • AbstractGraphQLRequest

        public AbstractGraphQLRequest​(java.lang.String schema,
                                      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:
        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​(java.lang.String schema,
                                      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:
        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 Detail

      • 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
      • buildRequestAsString

        public java.lang.String buildRequestAsString​(java.util.Map<java.lang.String,​java.lang.Object> params)
                                              throws GraphQLRequestExecutionException
        Builds the request, and return it as a String
        Parameters:
        params - The parameters values to transmit to the server
        Returns:
        Throws:
        GraphQLRequestExecutionException
      • getJsonRequest

        public java.lang.String getJsonRequest​(java.util.Map<java.lang.String,​java.lang.Object> parameters)
                                        throws GraphQLRequestExecutionException
        Returns the json string to be send to the GraphQL server, for execution of this request
        Parameters:
        parameters - The map that contains each parameters (key=parameter name, value=parameter value)
        Returns:
        Throws:
        GraphQLRequestExecutionException
      • buildRequestAsMap

        public java.util.Map<java.lang.String,​java.lang.Object> buildRequestAsMap​(java.util.Map<java.lang.String,​java.lang.Object> params)
                                                                                 throws GraphQLRequestExecutionException
        Builds the request, and return it as a String
        Parameters:
        params - The parameters values to transmit to the server
        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:
      • getSubscription

        public QueryField getSubscription()
      • getFragments

        public java.util.List<Fragment> getFragments()
      • 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