Class GraphQLRequest
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
- Author:
- generated by graphql-java-generator
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.graphql_java_generator.client.request.AbstractGraphQLRequest
AbstractGraphQLRequest.Payload
-
Field Summary
Fields inherited from class com.graphql_java_generator.client.request.AbstractGraphQLRequest
packageName
-
Constructor Summary
ConstructorDescriptionGraphQLRequest
(String graphQLRequest) Creates the GraphQL request, for a full request.GraphQLRequest
(org.springframework.graphql.client.GraphQlClient graphQlClient, String graphQLRequest, com.graphql_java_generator.annotation.RequestType requestType, String fieldName, InputParameter... inputParams) 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. -
Method Summary
Modifier and TypeMethodDescriptionexecMutation
(Object... paramsAndValues) This method executes the current GraphQL request as a full mutation request.execMutation
(Map<String, Object> parameters) This method executes the current GraphQL request as a full mutation request.This method executes the current GraphQL request as a full query request.This method executes the current GraphQL request as a full query request.execSubscription
(SubscriptionCallback<T> subscriptionCallback, Class<T> messageType, Object... paramsAndValues) This method executes the current GraphQL request as a full subscription request.execSubscription
(SubscriptionCallback<T> subscriptionCallback, Class<T> messageType, Map<String, Object> parameters) This method executes the current GraphQL request as a full subscription request.protected String
This method returns the package name, where the GraphQL generated classes are.Class<? extends GraphQLRequestObject>
Methods inherited from class com.graphql_java_generator.client.request.AbstractGraphQLRequest
exec, exec, execReactive, execReactive, getFragments, getGraphQLObjectMapper, getGraphQLRequest, getMutation, getPayload, getQuery, getRequestName, getRequestType, getSubscription, logExecution
-
Constructor Details
-
GraphQLRequest
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' theGraphQlClient
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
- TheGraphQlClient
that is responsible for the actual execution of the requestgraphQLRequest
- 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 subscriptionfieldName
- 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
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 emptyMap
- 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
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
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 emptyMap
- 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
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 GraphQLRequestExecutionExceptionThis 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
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 classparameters
- 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 emptyMap
- 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
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 classparamsAndValues
- 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
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 classAbstractGraphQLRequest
- Returns:
-
getQueryContext
- Specified by:
getQueryContext
in classAbstractGraphQLRequest
- Throws:
GraphQLRequestPreparationException
-
getMutationContext
- Specified by:
getMutationContext
in classAbstractGraphQLRequest
- Throws:
GraphQLRequestPreparationException
-
getSubscriptionContext
- Specified by:
getSubscriptionContext
in classAbstractGraphQLRequest
- Throws:
GraphQLRequestPreparationException
-
getSubscriptionClass
- Specified by:
getSubscriptionClass
in classAbstractGraphQLRequest
-