Class InputParameter
java.lang.Object
com.graphql_java_generator.client.request.InputParameter
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumIndicates the kind of parameter -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInputParameter(String schema, String name, String parameterName, Object value, InputParameter.InputParameterType type, Directive directive, Class<?> owningClass, String fieldName) The constructor is private.protectedInputParameter(String schema, String name, String bindParameterName, Object defaultValue, InputParameter.InputParameterType type, String graphQLTypeName, boolean mandatory, int listDepth, boolean itemMandatory) The constructor is private. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendInputParametersToGraphQLRequests(boolean writingGraphQLVariables, StringBuilder sb, List<InputParameter> inputParameters, Map<String, Object> parameters) protected voidappendStringContentForGraphqlQueryFromMap(StringBuilder sb, Map<?, ?> map) Write a map as a valid GraphQL string for an input parameter, into a GraphQL query.protected voidWrite a list as a valid GraphQL string for an input parameter, into a GraphQL query.protected voidWrite a list as a valid GraphQL string for an input parameter, into a GraphQL query.Returns the default parameter value, properly formated,for inclusion as default value in a GraphQL query.graphql.schema.GraphQLScalarTypeintgetName()protected StringgetQuotedString(String str) Escape a string in accordance with the rules defined for JSON strings so that it can be included in a GraphQL payload.protected StringgetStringContentForAListValue(boolean writingGraphQLVariables, Object list, int listDepth, graphql.schema.GraphQLScalarType graphQLScalarTypeParam, boolean graphQLVariable) This method returns the JSON string that represents the given list, according to GraphQL standard.protected StringgetStringContentForAnInputTypeValue(boolean writingGraphQLVariables, Object object, int listDepth, boolean graphQLVariable) This method returns the JSON string that represents the given object, according to GraphQL standard.protected StringgetStringContentForGraphqlQuery(boolean writingGraphQLVariables, Object val, int listDepth, graphql.schema.GraphQLScalarType graphQLScalarTypeParam, boolean graphQLVariable) This method is used both by#getValueForGraphqlQuery()and#getListValue(List)to extract a value as a string.getStringContentForGraphqlQuery(boolean writingGraphQLVariables, Map<String, Object> bindVariables) Returns the parameter, as it should be written in the GraphQL query.getType()getValueForGraphqlQuery(Map<String, Object> bindVariables) Returns the parameter value, as-is, without any escape characterbooleanbooleanstatic InputParameternewBindParameter(String schema, String name, String bindParameterName, InputParameter.InputParameterType type, String graphQLTypeName, boolean mandatory, int listDepth, boolean itemMandatory) Creates and returns a new instance ofInputParameter, which is bound to a bind variable.static InputParameternewGraphQLVariableParameter(String schema, String name, Object defaultValue, String graphQLTypeName, boolean mandatory, int listDepth, boolean itemMandatory) Creates and returns a new instance ofInputParameter, which value is given, and can not be changed afterwards.static InputParameternewHardCodedParameter(String schema, String name, Object value, String graphQLTypeName, boolean mandatory, int listDepth, boolean itemMandatory) Creates and returns a new instance ofInputParameter, which value is given, and can not be changed afterwards.static ObjectparseValueForInputParameter(Object parameterValue, String schema, String parameterTypeName) Parse a value, depending on the parameter type.static List<InputParameter>readTokenizerForInputParameters(QueryTokenizer qt, Directive directive, Class<?> owningClass, String fieldName, String schema) Reads a list of input parameters, from aQueryTokenizer.
-
Constructor Details
-
InputParameter
protected InputParameter(String schema, String name, String bindParameterName, Object defaultValue, InputParameter.InputParameterType type, String graphQLTypeName, boolean mandatory, int listDepth, boolean itemMandatory) The constructor is private. Instances must be created with one of these helper methods:#newBindParameter(String, String)or#newHardCodedParameter(String, Object)- Parameters:
schema- 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.name- The parameter name, as defined in the GraphQL schemabindParameterName- The name of the bind parameter, as defined in the GraphQL response definition. If null, it's a hard coded value. The value will be sent to the server, when the request is executed. Please read the client doc for more information on input parameters and bind variables.defaultValue- The value to send, for this input parameter. If null, it's a bind parameter. The bindParameterName is then mandatory.type- The kind ofInputParameterto creategraphQLTypeName- The GraphQL type name of this parameter. For instance: "Human", for the type "[[Human]]"mandatory- True if this parameter is mandatorylistDepth- The depth of the list for this input parameter: 0 if this parameter is not a list. And 2, for instance, if the parameter's type is "[[Int]]"itemMandatory- Used only if this parameter is a list. In this case: true if the item of the list are mandatory, false otherwise
-
InputParameter
protected InputParameter(String schema, String name, String parameterName, Object value, InputParameter.InputParameterType type, Directive directive, Class<?> owningClass, String fieldName) throws GraphQLRequestPreparationException The constructor is private. Instances must be created with one of these helper methods:#newBindParameter(String, String)or#newHardCodedParameter(String, Object)- Parameters:
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.name- The parameter name, as defined in the GraphQL schemaparameterName- The name of the bind parameter, as defined in the GraphQL response definition. If null, it's a hard coded value. The value will be sent to the server, when the request is executed. Please read the client doc for more information on input parameters and bind variables.value- The value to send, for this input parameter. If null, it's a bind parameter. The bindParameterName is then mandatory.type- The kind ofInputParameterto createdirective- If not null, then we're looking for an argument of a GraphQL directive. Oherwise, it's a field argument, and the owningClass and fieldName parameters will be used.owningClass- The class that contains this fieldfieldName- The field name- Throws:
GraphQLRequestPreparationException
-
-
Method Details
-
newBindParameter
public static InputParameter newBindParameter(String schema, String name, String bindParameterName, InputParameter.InputParameterType type, String graphQLTypeName, boolean mandatory, int listDepth, boolean itemMandatory) 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:
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.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.type- The kind ofInputParameterto creategraphQLTypeName- The GraphQL type name of this parameter. For instance: "Human", for the type "[[Human]]"mandatory- True if this parameter is mandatorylistDepth- The depth of the list for this input parameter: 0 if this parameter is not a list. And 2, for instance, if the parameter's type is "[[Int]]"itemMandatory- Used only if this parameter is a list. In this case: true if the item of the list are mandatory, false otherwise- Returns:
- The newly created
InputParameter, according to these parameters - See Also:
-
RequestExecutionSpringReactiveImpl#execute(String, ObjectResponse, List, Class)
-
newGraphQLVariableParameter
public static InputParameter newGraphQLVariableParameter(String schema, String name, Object defaultValue, String graphQLTypeName, boolean mandatory, int listDepth, boolean itemMandatory) Creates and returns a new instance ofInputParameter, which value is given, and can not be changed afterwards.- Parameters:
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.name- The parameter name, as defined in the GraphQL schemadefaultValue- Optional default value for parametergraphQLTypeName- The GraphQL type name of this parameter. For instance: "Human", for the type "[[Human]]"mandatory- True if this parameter is mandatorylistDepth- The depth of the list for this input parameter: 0 if this parameter is not a list. And 2, for instance, if the parameter's type is "[[Int]]"itemMandatory- Used only if this parameter is a list. In this case: true if the item of the list are mandatory, false otherwise- Returns:
- The newly created
InputParameter, according to these parameters
-
newHardCodedParameter
public static InputParameter newHardCodedParameter(String schema, String name, Object value, String graphQLTypeName, boolean mandatory, int listDepth, boolean itemMandatory) Creates and returns a new instance ofInputParameter, which value is given, and can not be changed afterwards.- Parameters:
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.name- The parameter name, as defined in the GraphQL schemavalue- The value to send, for this input parameter. If null, it's a bind parameter. The bindParameterName is then mandatory.graphQLTypeName- The GraphQL type name of this parameter. For instance: "Human", for the type "[[Human]]"mandatory- True if this parameter is mandatorylistDepth- The depth of the list for this input parameter: 0 if this parameter is not a list. And 2, for instance, if the parameter's type is "[[Int]]"itemMandatory- Used only if this parameter is a list. In this case: true if the item of the list are mandatory, false otherwise- Returns:
- The newly created
InputParameter, according to these parameters
-
readTokenizerForInputParameters
public static List<InputParameter> readTokenizerForInputParameters(QueryTokenizer qt, Directive directive, Class<?> owningClass, String fieldName, String schema) throws GraphQLRequestPreparationException Reads 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 thisDirectiveowningClass- 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.- Throws:
GraphQLRequestPreparationException- If the request string is invalid
-
parseValueForInputParameter
public static Object parseValueForInputParameter(Object parameterValue, String schema, String parameterTypeName) throws GraphQLRequestPreparationException Parse a value, depending on the parameter type.- Parameters:
parameterValue-schema-parameterTypeName-packageName- 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.- Returns:
- Throws:
GraphQLRequestPreparationExceptionRuntimeException- When the value could be parsed
-
getName
-
getDefaultValueForGraphqlQuery
Returns the default parameter value, properly formated,for inclusion as default value in a GraphQL query.- Returns:
-
getValueForGraphqlQuery
Returns the parameter value, as-is, without any escape character- 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
-
getStringContentForGraphqlQuery
public String getStringContentForGraphqlQuery(boolean writingGraphQLVariables, Map<String, 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:
writingGraphQLVariables- true if this call is done, while writing the value for the "variables" field of the json request.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
-
getStringContentForGraphqlQuery
protected String getStringContentForGraphqlQuery(boolean writingGraphQLVariables, Object val, int listDepth, graphql.schema.GraphQLScalarType graphQLScalarTypeParam, boolean graphQLVariable) throws GraphQLRequestExecutionException This method is used both by#getValueForGraphqlQuery()and#getListValue(List)to extract a value as a string.- Parameters:
writingGraphQLVariables- true if this call is done, while writing the value for the "variables" field of the json request.val- This value of the parameter. It can be thedefaultValueif it is not null, or the binding from the bind parameters. It's up to the caller to map the bind parameter into this method argument.listDepth- The expected list depth for the value. listDepth is 0 if val should not be a list, 1 if val should be a list, 2 if val should be a list of list...graphQLTypeNameParam-graphQLScalarTypeParam- TheGraphQLScalarTypefor this value. It may be the same as the parameter one (for scalar), or the one of the current field (for input types).graphQLVariable- true if the current input type should be deserialize as a GraphQL variable. In this case, it's deserialized as a map. So the field names must be within double quotes- Returns:
- Throws:
GraphQLRequestExecutionException
-
appendStringContentForGraphqlQueryFromMap
Write a map as a valid GraphQL string for an input parameter, into a GraphQL query. This is mandatory for the Object scalar.- Parameters:
map- The map to be written into the GraphQL request- Throws:
GraphQLRequestExecutionException
-
appendStringContentForGraphqlQueryFromMapForAListItem
protected void appendStringContentForGraphqlQueryFromMapForAListItem(StringBuilder sb, List<?> list) Write a list as a valid GraphQL string for an input parameter, into a GraphQL query. This method should only be called fromappendStringContentForGraphqlQueryFromMap(StringBuilder, Map), in order to render a value of the map which is a list.- Parameters:
sb-list-
-
appendStringContentForGraphqlQueryFromValueItem
Write a list as a valid GraphQL string for an input parameter, into a GraphQL query. This method should only be called fromappendStringContentForGraphqlQueryFromMap(StringBuilder, Map)orappendStringContentForGraphqlQueryFromMapForAListItem(StringBuilder, List), in order to render a value of the map or a list.- Parameters:
sb-value-- Throws:
GraphQLRequestExecutionException
-
getQuotedString
Escape a string in accordance with the rules defined for JSON strings so that it can be included in a GraphQL payload. Because a GraphQL request consists of stringified JSON objects wrapped in another JSON object, the escaping is applied twice.- Parameters:
str- The String value that should be formated for the GraphQL request- Returns:
- escaped string
- See Also:
-
getStringContentForAListValue
protected String getStringContentForAListValue(boolean writingGraphQLVariables, Object list, int listDepth, graphql.schema.GraphQLScalarType graphQLScalarTypeParam, boolean graphQLVariable) throws GraphQLRequestExecutionException This method returns the JSON string that represents the given list, according to GraphQL standard. This method is used to write a part of the GraphQL client query that will be sent to the server.- Parameters:
writingGraphQLVariables- true if this call is done, while writing the value for the "variables" field of the json request.list- a non null List or arraylistDepth- The expected list depth for the value. listDepth is 0 if val should not be a list, 1 if val should be a list, 2 if val should be a list of list...graphQLScalarTypeParam- TheGraphQLScalarTypefor this value. It may be the same as the parameter one (for scalar), or the one of the current field (fot input types).- Returns:
- Throws:
GraphQLRequestExecutionExceptionNullPointerException- If list is null
-
getStringContentForAnInputTypeValue
protected String getStringContentForAnInputTypeValue(boolean writingGraphQLVariables, Object object, int listDepth, boolean graphQLVariable) throws GraphQLRequestExecutionException This method returns the JSON string that represents the given object, according to GraphQL standard. This method is used to write a part of the GraphQL client query that will be sent to the server.- Parameters:
writingGraphQLVariables- true if this call is done, while writing the value for the "variables" field of the json request.object- An object which class is an InputType as defined in the GraphQL schemalistDepth- The expected list depth for the value. listDepth is 0 if val should not be a list, 1 if val should be a list, 2 if val should be a list of list...graphQLVariable- true if the current input type should be deserialize as a GraphQL variable. In this case, it's deserialized as a map. So the field names must be within double quotes- Returns:
- The String that represents this object, according to GraphQL standard representation, as expected in the query to be sent to the server
- Throws:
GraphQLRequestExecutionException
-
getBindParameterName
-
getType
-
getGraphQLTypeName
-
getGraphQLScalarType
public graphql.schema.GraphQLScalarType getGraphQLScalarType() -
isItemMandatory
public boolean isItemMandatory() -
getListDepth
public int getListDepth() -
isMandatory
public boolean isMandatory() -
appendInputParametersToGraphQLRequests
public static void appendInputParametersToGraphQLRequests(boolean writingGraphQLVariables, StringBuilder sb, List<InputParameter> inputParameters, Map<String, Object> parameters) throws GraphQLRequestExecutionException- Parameters:
writingGraphQLVariables- true if this call is done, while writing the value for the "variables" field of the json request.sb-inputParameters-parameters-- Throws:
GraphQLRequestExecutionException
-