java.lang.Object
com.graphql_java_generator.client.request.InputParameter

public class InputParameter extends 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
    • 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 schema
        bindParameterName - 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 of InputParameter to create
        graphQLTypeName - The GraphQL type name of this parameter. For instance: "Human", for the type "[[Human]]"
        mandatory - True if this parameter is mandatory
        listDepth - 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 schema
        parameterName - 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 of InputParameter to create
        directive - 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 field
        fieldName - 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 of InputParameter, 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 of InputParameter to create
        graphQLTypeName - The GraphQL type name of this parameter. For instance: "Human", for the type "[[Human]]"
        mandatory - True if this parameter is mandatory
        listDepth - 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 of InputParameter, 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 schema
        defaultValue - Optional default value for parameter
        graphQLTypeName - The GraphQL type name of this parameter. For instance: "Human", for the type "[[Human]]"
        mandatory - True if this parameter is mandatory
        listDepth - 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 of InputParameter, 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 schema
        value - 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 mandatory
        listDepth - 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 a QueryTokenizer. 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 this Directive
        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.
        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:
        GraphQLRequestPreparationException
        RuntimeException - When the value could be parsed
      • getName

        public String getName()
      • getDefaultValueForGraphqlQuery

        public Object getDefaultValueForGraphqlQuery()
        Returns the default parameter value, properly formated,for inclusion as default value in a GraphQL query.
        Returns:
      • getValueForGraphqlQuery

        public Object getValueForGraphqlQuery(Map<String,Object> bindVariables)
        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 in bindParameterName.
        Returns:
        Throws:
        GraphQLRequestExecutionException
      • getStringContentForGraphqlQuery

        public String getStringContentForGraphqlQuery(boolean writingGraphQLVariables, Map<String,Object> bindVariables) throws GraphQLRequestExecutionException
        Returns 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 in bindParameterName.
        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 the defaultValue if 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 - The GraphQLScalarType for 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

        protected void appendStringContentForGraphqlQueryFromMap(StringBuilder sb, Map<?,?> map)
        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 from appendStringContentForGraphqlQueryFromMap(StringBuilder, Map), in order to render a value of the map which is a list.
        Parameters:
        sb -
        list -
      • appendStringContentForGraphqlQueryFromValueItem

        protected void appendStringContentForGraphqlQueryFromValueItem(StringBuilder sb, Object value)
        Write a list as a valid GraphQL string for an input parameter, into a GraphQL query. This method should only be called from appendStringContentForGraphqlQueryFromMap(StringBuilder, Map) or appendStringContentForGraphqlQueryFromMapForAListItem(StringBuilder, List), in order to render a value of the map or a list.
        Parameters:
        sb -
        value -
        Throws:
        GraphQLRequestExecutionException
      • getQuotedString

        protected String getQuotedString(String str)
        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 array
        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...
        graphQLScalarTypeParam - The GraphQLScalarType for 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:
        GraphQLRequestExecutionException
        NullPointerException - 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 schema
        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...
        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

        public String getBindParameterName()
      • getType

      • getGraphQLTypeName

        public String 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