Class InputParameter
java.lang.Object
com.graphql_java_generator.client.request.InputParameter
public class InputParameter
extends java.lang.Object
Contains an input parameter, to be sent to a query (mutation...). It can be either:
-
A hard coded value
-
A bind variable, which value must be provided when executing the query
- Author:
- etienne-sf
-
Method Summary
Modifier and Type Method Description static void
appendInputParametersToGraphQLRequests(java.lang.StringBuilder sb, java.util.List<InputParameter> inputParameters, java.util.Map<java.lang.String,java.lang.Object> parameters)
java.lang.String
getBindParameterName()
graphql.schema.GraphQLScalarType
getGraphQLScalarType()
java.lang.String
getName()
java.lang.Object
getValue()
java.lang.String
getValueForGraphqlQuery(java.util.Map<java.lang.String,java.lang.Object> bindVariables)
Returns the parameter, as it should be written in the GraphQL query.boolean
isMandatory()
static InputParameter
newBindParameter(java.lang.String name, java.lang.String bindParameterName, boolean mandatory)
Creates and returns a new instance ofInputParameter
, which is bound to a bind variable.static InputParameter
newBindParameter(java.lang.String name, java.lang.String bindParameterName, boolean mandatory, graphql.schema.GraphQLScalarType graphQLScalarType)
Creates and returns a new instance ofInputParameter
, which is bound to a bind variable.static InputParameter
newHardCodedParameter(java.lang.String name, java.lang.Object value)
Creates and returns a new instance ofInputParameter
, which value is given, and can not be changed afterwardsstatic InputParameter
newHardCodedParameter(java.lang.String name, java.lang.Object value, boolean mandatory, graphql.schema.GraphQLScalarType type)
Creates and returns a new instance ofInputParameter
, which value is given, and can not be changed afterwards.static java.util.List<InputParameter>
readTokenizerForInputParameters(QueryTokenizer qt, Directive directive, java.lang.Class<?> owningClass, java.lang.String fieldName)
Reads a list of input parameters, from aQueryTokenizer
.
-
Method Details
-
newBindParameter
public static InputParameter newBindParameter(java.lang.String name, java.lang.String bindParameterName, boolean mandatory)Creates and returns a new instance ofInputParameter
, which is bound to a bind variable. The value for this bind variable must be provided, when calling the request execution.- Parameters:
name
-bindParameterName
- The name of the bind parameter, as defined in the GraphQL response definition. It is mandator for bind parameters, so it may not be null here. Please read the client doc for more information on input parameters and bind variables.mandatory
- true if the parameter's value must be defined during request/mutation/subscription execution.
If mandatory is true and the parameter's value is not provided, aGraphQLRequestExecutionException
exception is thrown at execution time
If mandatory is false and the parameter's value is not provided, this input parameter is not sent to the server- Returns:
- See Also:
QueryExecutorImpl#execute(String, ObjectResponse, List, Class)
-
newBindParameter
public static InputParameter newBindParameter(java.lang.String name, java.lang.String bindParameterName, boolean mandatory, graphql.schema.GraphQLScalarType graphQLScalarType)Creates and returns a new instance ofInputParameter
, which is bound to a bind variable. The value for this bind variable must be provided, when calling the request execution.- Parameters:
name
-bindParameterName
- The name of the bind parameter, as defined in the GraphQL response definition. It is mandator for bind parameters, so it may not be null here. Please read the client doc for more information on input parameters and bind variables.mandatory
- true if the parameter's value must be defined during request/mutation/subscription execution.
If mandatory is true and the parameter's value is not provided, aGraphQLRequestExecutionException
exception is thrown at execution time
If mandatory is false and the parameter's value is not provided, this input parameter is not sent to the servergraphQLCustomScalarType
- If this input parameter's type is a GraphQL Custom Scalar, it must be provided. Otherwise, it must be null.
graphQLCustomScalarType contains theGraphQLScalarType
that allows to convert the value to a String that can be written in the GraphQL request, or convert from a String that is found in the GraphQL response. If this type is not a GraphQL Custom Scalar, it must be null.- Returns:
- See Also:
QueryExecutorImpl#execute(String, ObjectResponse, List, Class)
-
newHardCodedParameter
Creates and returns a new instance ofInputParameter
, which value is given, and can not be changed afterwards- Parameters:
name
-value
-- Returns:
-
newHardCodedParameter
public static InputParameter newHardCodedParameter(java.lang.String name, java.lang.Object value, boolean mandatory, graphql.schema.GraphQLScalarType type)Creates and returns a new instance ofInputParameter
, which value is given, and can not be changed afterwards.- Parameters:
name
-value
-mandatory
-type
-- Returns:
-
readTokenizerForInputParameters
public static java.util.List<InputParameter> readTokenizerForInputParameters(QueryTokenizer qt, Directive directive, java.lang.Class<?> owningClass, java.lang.String fieldName) throws GraphQLRequestPreparationExceptionReads a list of input parameters, from aQueryTokenizer
. It can be the list of parameters for a Field or for a Directive. It can be either a Field of a Query, Mutation or Subscription, or a Field of a standard GraphQL Type, or any directive...- Parameters:
qt
- The StringTokenizer, where the opening parenthesis has been read. It will be read until and including the next closing parenthesis.directive
- if not null, then this method is reading the input parameters (arguments) for thisDirective
owningClass
- if not null, then this method is reading the input parameters for the field fieldName of this class.fieldName
- if owningClass, this is the name of the field, whose input parameters are being read.packageName
- The package name is necessary to load the generated classes, to read the metadata that has been generated- Throws:
GraphQLRequestPreparationException
- If the request string is invalid
-
getName
public java.lang.String getName() -
getValue
public java.lang.Object getValue() -
getValueForGraphqlQuery
public java.lang.String getValueForGraphqlQuery(java.util.Map<java.lang.String,java.lang.Object> bindVariables) throws GraphQLRequestExecutionExceptionReturns the parameter, as it should be written in the GraphQL query. For instance:- String: a "string" -> "a \"string\""
- Enum: EPISODE -> EPISODE (no escape or double quote here)
- Parameters:
bindVariables
- The map for the bind variables. It may be null, if this input parameter is a hard coded one. If this parameter is a Bind Variable, then bindVariables is mandatory, and it must contain a value for th bind parameter which name is stored inbindParameterName
.- Returns:
- Throws:
GraphQLRequestExecutionException
-
getBindParameterName
public java.lang.String getBindParameterName() -
isMandatory
public boolean isMandatory() -
getGraphQLScalarType
public graphql.schema.GraphQLScalarType getGraphQLScalarType() -
appendInputParametersToGraphQLRequests
public static void appendInputParametersToGraphQLRequests(java.lang.StringBuilder sb, java.util.List<InputParameter> inputParameters, java.util.Map<java.lang.String,java.lang.Object> parameters) throws GraphQLRequestExecutionException- Throws:
GraphQLRequestExecutionException
-