java.lang.Object
com.graphql_java_generator.client.request.AbstractGraphQLRequest
com.graphql_java_generator.client.request.ObjectResponse
com.graphql_java_generator.samples.forum.client.graphql.forum.client.util.GraphQLRequest

public class GraphQLRequest extends ObjectResponse
Author:
generated by graphql-java-generator
See Also:
  • Constructor Details

    • GraphQLRequest

      public GraphQLRequest(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.

      This method will 'guess' the GraphQlClient to use, in order to execute the client. This means that, when using a GraphQL client that can attack several servers, you must use the relevant GraphQLRequest class, that is: the one generated in the relevant folder, along with the other classes for this schema.
      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
    • GraphQLRequest

      public GraphQLRequest(org.springframework.graphql.client.GraphQlClient graphQlClient, String graphQLRequest, com.graphql_java_generator.annotation.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 NOT 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
      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
  • Method Details

    • execQuery

      public Query execQuery(Map<String,Object> parameters) throws GraphQLRequestExecutionException
      This method executes the current GraphQL request as a full query request. It offers a logging of the call (if in debug mode), or of the call and its parameters (if in trace mode).
      Here is a sample (and please have a look to the graphql-java-generator website for more information):
       GraphQLRequest request;
       
       public void setup() {
        GraphQLRequest.setStaticConfiguration(...);
              // Preparation of the query
              request = myQueryType.getResponseBuilder()
                              .withQueryResponseDef("query{hero(param:?heroParam) @include(if:true) {id name @skip(if: ?skip) appearsIn friends {id name}}}").build();
       }
       
       public void doTheJob() {
         ..
         Map<String, Object> params = new HashMap<>();
         params.put("heroParam", heroParamValue);
         params.put("skip", Boolean.FALSE);
         // This will set the value sinceValue to the sinceParam field parameter
         Query response = request.execQuery(params);
         ...
       }
       
      Parameters:
      parameters - The list of values, for the bind variables defined in the query. If there is no bind variable in the defined Query, this argument may be null or an empty Map
      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
    • execQuery

      public Query execQuery(Object... paramsAndValues) throws GraphQLRequestExecutionException
      This method executes the current GraphQL request as a full query request. It offers a logging of the call (if in debug mode), or of the call and its parameters (if in trace mode).
      Here is a sample (and please have a look to the graphql-java-generator website for more information):
       GraphQLRequest request;
       
       public void setup() {
        GraphQLRequest.setStaticConfiguration(...);
              // Preparation of the query
              request = new GraphQLRequest("query{hero(param:?heroParam) @include(if:true) {id name @skip(if: ?skip) appearsIn friends {id name}}}").build();
       }
       
       public void doTheJob() {
         ..
         // This will set the value sinceValue to the sinceParam field parameter
         Query response = request.execQuery("heroParam", heroParamValue, "skip", Boolean.FALSE);
         ...
       }
       
      Parameters:
      paramsAndValues - This parameter contains all the name and values for the Bind Variables defined in the objectResponse parameter, that must be sent to the server. Optional parameter may not have a value. They will be ignored and not sent to the server. Mandatory parameter must be provided in this argument.
      This parameter contains an even number of parameters: it must be a series of name and values : (paramName1, paramValue1, paramName2, paramValue2...)
      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
    • execMutation

      public Mutation execMutation(Map<String,Object> parameters) throws GraphQLRequestExecutionException
      This method executes the current GraphQL request as a full mutation request. It offers a logging of the call (if in debug mode), or of the call and its parameters (if in trace mode).
      Here is a sample (and please have a look to the graphql-java-generator website for more information):
       GraphQLRequest request;
       
       public void setup() {
        GraphQLRequest.setStaticConfiguration(...);
              // Preparation of the query
              request = myQueryType.getResponseBuilder()
                              .withQueryResponseDef("mutation{hero(param:?heroParam) @include(if:true) {id name @skip(if: ?skip) appearsIn friends {id name}}}").build();
       }
       
       public void doTheJob() {
        ..
         Map<String, Object> params = new HashMap<>();
         params.put("heroParam", heroParamValue);
         params.put("skip", Boolean.FALSE);
         // This will set the value sinceValue to the sinceParam field parameter
         Mutation response = request.execMutation(params);
         ...
       }
       
      Parameters:
      parameters - The list of values, for the bind variables defined in the query. If there is no bind variable in the defined Query, this argument may be null or an empty Map
      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
    • execMutation

      public Mutation execMutation(Object... paramsAndValues) throws GraphQLRequestExecutionException
      This method executes the current GraphQL request as a full mutation request. It offers a logging of the call (if in debug mode), or of the call and its parameters (if in trace mode).
      Here is a sample (and please have a look to the graphql-java-generator website for more information):
       GraphQLRequest request;
       
       public void setup() {
        GraphQLRequest.setStaticConfiguration(...);
              // Preparation of the query
              request = new GraphQLRequest("mutation{hero(param:?heroParam) @include(if:true) {id name @skip(if: ?skip) appearsIn friends {id name}}}").build();
       }
       
       public void doTheJob() {
         ..
         // This will set the value sinceValue to the sinceParam field parameter
         Mutation response = request.execMutation("heroParam", heroParamValue, "skip", Boolean.FALSE);
         ...
       }
       
      Parameters:
      paramsAndValues - This parameter contains all the name and values for the Bind Variables defined in the objectResponse parameter, that must be sent to the server. Optional parameter may not have a value. They will be ignored and not sent to the server. Mandatory parameter must be provided in this argument.
      This parameter contains an even number of parameters: it must be a series of name and values : (paramName1, paramValue1, paramName2, paramValue2...)
      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
    • execSubscription

      public <T> SubscriptionClient execSubscription(SubscriptionCallback<T> subscriptionCallback, Class<T> messageType, Map<String,Object> parameters) throws GraphQLRequestExecutionException
      This method executes the current GraphQL request as a full subscription request. It offers a logging of the call (if in debug mode), or of the call and its parameters (if in trace mode). You can to the graphql-java-generator website to read more information.
      Please note:
      • Using partial request is easier
      • The full request may bot contain more than one subscription at a time
      Here is a sample (and please have a look to the GraphQL site for more information):
       GraphQLRequest request;
       
       public void setup() {
         GraphQLRequest.setStaticConfiguration(...);
               // Preparation of the query
               request = myQueryType.getResponseBuilder()
                              .withQueryResponseDef("subscription{hero(param:?heroParam) @include(if:true) {id name @skip(if: ?skip) appearsIn friends {id name}}}").build();
       }
       
       public void doTheJob() {
         ..
         Map<String, Object> params = new HashMap<>();
         params.put("heroParam", heroParamValue);
         params.put("skip", Boolean.FALSE);
         // This will set the value sinceValue to the sinceParam field parameter
         SubscriptionClient subClient = request.execSubscription(subscriptionCallback, Character.class, params);
         ...
       }
       
      Type Parameters:
      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:
      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.
      messageType - The T class
      parameters - The list of values, for the bind variables defined in the query. If there is no bind variable in the defined Query, this argument may be null or an empty Map
      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
    • execSubscription

      public <T> SubscriptionClient execSubscription(SubscriptionCallback<T> subscriptionCallback, Class<T> messageType, Object... paramsAndValues) throws GraphQLRequestExecutionException
      This method executes the current GraphQL request as a full subscription request. It offers a logging of the call (if in debug mode), or of the call and its parameters (if in trace mode). You can to the graphql-java-generator website to read more information.
      Please note:
      • Using partial request is easier
      • The full request may bot contain more than one subscription at a time
      Here is a sample (and please have a look to the GraphQL site for more information):
       GraphQLRequest request;
       
       public void setup() {
        GraphQLRequest.setStaticConfiguration(...);
              // Preparation of the query
              request = new GraphQLRequest("subscription{hero(param:?heroParam) @include(if:true) {id name @skip(if: ?skip) appearsIn friends {id name}}}").build();
       }
       
       public void doTheJob() {
         ..
         // This will set the values for the heroParam and skip parameters
         SubscriptionClient subClient = request.execSubscription(subscriptionCallback, Character.class, "heroParam", heroParamValue, "skip", Boolean.FALSE);
         ...
       }
       
      Type Parameters:
      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:
      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.
      messageType - The T class
      paramsAndValues - This parameter contains all the name and values for the Bind Variables defined in the objectResponse parameter, that must be sent to the server. Optional parameter may not have a value. They will be ignored and not sent to the server. Mandatory parameter must be provided in this argument.
      This parameter contains an even number of parameters: it must be a series of name and values : (paramName1, paramValue1, paramName2, paramValue2...)
      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
    • getGraphQLClassesPackageName

      protected 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.
      Specified by:
      getGraphQLClassesPackageName in class AbstractGraphQLRequest
      Returns:
    • getQueryContext

      public QueryField getQueryContext() throws GraphQLRequestPreparationException
      Specified by:
      getQueryContext in class AbstractGraphQLRequest
      Throws:
      GraphQLRequestPreparationException
    • getMutationContext

      public QueryField getMutationContext() throws GraphQLRequestPreparationException
      Specified by:
      getMutationContext in class AbstractGraphQLRequest
      Throws:
      GraphQLRequestPreparationException
    • getSubscriptionContext

      public QueryField getSubscriptionContext() throws GraphQLRequestPreparationException
      Specified by:
      getSubscriptionContext in class AbstractGraphQLRequest
      Throws:
      GraphQLRequestPreparationException
    • getSubscriptionClass

      public Class<? extends GraphQLRequestObject> getSubscriptionClass()
      Specified by:
      getSubscriptionClass in class AbstractGraphQLRequest