Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,15 @@ private void readRequestParameters(QueryTokenizer qt, List<InputParameter> input
} else {
mandatory = false;
}

Object defaultValue = null;
if (qt.checkNextToken("=")) {
token = qt.nextToken();
token = qt.nextToken();
defaultValue = token;
}

inputParameters.add(InputParameter.newGraphQLVariableParameter(schema, name, graphQLTypeName, mandatory,
inputParameters.add(InputParameter.newGraphQLVariableParameter(schema, name, defaultValue, graphQLTypeName, mandatory,
listDepth, itemMandatory));
// The next token should be either the end of parameters (with a ')') or a name
step = Step.NAME;
Expand Down Expand Up @@ -882,6 +889,11 @@ public Payload getPayload(Map<String, Object> params) throws GraphQLRequestExecu
//////////////////////////////////////////////////////////////////////
// And the variable value list (for the json variables field)
payload.variables.put(param.getBindParameterName(), param.getValueForGraphqlQuery(params));

if (param.getValue() != null) {
sbGraphQLVariables.append("=");
sbGraphQLVariables.append(param.getValue());
}

separator = ","; //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public static InputParameter newBindParameter(String schema, String name, String
* schema, this plugin parameter is usually not set. In this case, its default value ("") is used.
* @param name
* The parameter name, as defined in the GraphQL schema
* @param value
* Optional default value for parameter
* @param graphQLTypeName
* The GraphQL type name of this parameter. For instance: "Human", for the type "[[Human]]"
* @param mandatory
Expand All @@ -177,9 +179,9 @@ public static InputParameter newBindParameter(String schema, String name, String
* otherwise
* @return The newly created {@link InputParameter}, according to these parameters
*/
public static InputParameter newGraphQLVariableParameter(String schema, String name, String graphQLTypeName,
public static InputParameter newGraphQLVariableParameter(String schema, String name, Object value, String graphQLTypeName,
boolean mandatory, int listDepth, boolean itemMandatory) {
return new InputParameter(schema, name, name, null, InputParameterType.GRAPHQL_VARIABLE, graphQLTypeName,
return new InputParameter(schema, name, name, value, InputParameterType.GRAPHQL_VARIABLE, graphQLTypeName,
mandatory, listDepth, itemMandatory);
}

Expand Down Expand Up @@ -243,7 +245,7 @@ public static InputParameter newHardCodedParameter(String schema, String name, O
* Used only if this parameter is a list. In this case: true if the item of the list are mandatory, false
* otherwise
*/
private InputParameter(String schema, String name, String bindParameterName, Object value, InputParameterType type,
protected InputParameter(String schema, String name, String bindParameterName, Object value, InputParameterType type,
String graphQLTypeName, boolean mandatory, int listDepth, boolean itemMandatory) {
if (name == null) {
throw new NullPointerException("The input parameter's name is mandatory");
Expand Down Expand Up @@ -291,7 +293,7 @@ private InputParameter(String schema, String name, String bindParameterName, Obj
* The field name
* @throws GraphQLRequestPreparationException
*/
private InputParameter(String schema, String name, String parameterName, Object value, InputParameterType type,
protected InputParameter(String schema, String name, String parameterName, Object value, InputParameterType type,
Directive directive, Class<?> owningClass, String fieldName) throws GraphQLRequestPreparationException {
String localGraphQLCustomScalarType = null;
boolean localMandatory = false;
Expand Down Expand Up @@ -744,7 +746,7 @@ public String getStringContentForGraphqlQuery(boolean writingGraphQLVariables, M

// If the InputParameter is mandatory, which must have its value in the map of BindVariables.
if ((type.equals(InputParameterType.MANDATORY) || type.equals(InputParameterType.GRAPHQL_VARIABLE))
&& (bindVariables == null || !bindVariables.keySet().contains(bindParameterName))) {
&& ((bindVariables == null || !bindVariables.keySet().contains(bindParameterName)) && value == null)) {
throw new GraphQLRequestExecutionException(
"The Bind Parameter for '" + bindParameterName + "' must be provided in the BindVariables map");
}
Expand Down Expand Up @@ -779,15 +781,15 @@ public String getStringContentForGraphqlQuery(boolean writingGraphQLVariables, M
* @return
* @throws GraphQLRequestExecutionException
*/
String getStringContentForGraphqlQuery(boolean writingGraphQLVariables, Object val, int listDepth,
protected String getStringContentForGraphqlQuery(boolean writingGraphQLVariables, Object val, int listDepth,
String graphQLTypeNameParam, GraphQLScalarType graphQLScalarTypeParam, boolean graphQLVariable)
throws GraphQLRequestExecutionException {
if (val == null) {
return null;
} else if (graphQLVariable && !writingGraphQLVariables) {
// When writing a GraphQL variable in the query itself, then we write the variable name. The value is
// written only in the GraphQL variable field
return "$" + bindParameterName;
if (graphQLVariable && !writingGraphQLVariables) {
// When writing a GraphQL variable in the query itself, then we write the variable name. The value is
// written only in the GraphQL variable field
return "$" + bindParameterName;
} else if (val == null) {
return null;
} else if (listDepth > 0) {
// We expect val to be a list
return getStringContentForAListValue(writingGraphQLVariables, val, listDepth, graphQLTypeNameParam,
Expand Down Expand Up @@ -842,7 +844,7 @@ String getStringContentForGraphqlQuery(boolean writingGraphQLVariables, Object v
* @return
* @throws GraphQLRequestExecutionException
*/
private void appendStringContentForGraphqlQueryFromObjectNode(StringBuilder sb, JsonParser jsonParser,
protected void appendStringContentForGraphqlQueryFromObjectNode(StringBuilder sb, JsonParser jsonParser,
ObjectNode node) throws GraphQLRequestExecutionException {
try {

Expand Down Expand Up @@ -963,7 +965,7 @@ private void appendStringContentForGraphqlQueryFromObjectNode(StringBuilder sb,
* @return
* @throws GraphQLRequestExecutionException
*/
private void appendStringContentForGraphqlQueryFromMap(StringBuilder sb, Map<?, ?> map) {
protected void appendStringContentForGraphqlQueryFromMap(StringBuilder sb, Map<?, ?> map) {
boolean appendComma = false;// false for the first item, then true for others
sb.append('{');
for (Object key : map.keySet()) {
Expand Down Expand Up @@ -994,7 +996,7 @@ private void appendStringContentForGraphqlQueryFromMap(StringBuilder sb, Map<?,
* @param sb
* @param list
*/
private void appendStringContentForGraphqlQueryFromMapForAListItem(StringBuilder sb, List<?> list) {
protected void appendStringContentForGraphqlQueryFromMapForAListItem(StringBuilder sb, List<?> list) {
boolean appendComma = false;// false for the first item, then true for others
sb.append('[');
for (Object val : list) {
Expand Down Expand Up @@ -1022,7 +1024,7 @@ private void appendStringContentForGraphqlQueryFromMapForAListItem(StringBuilder
* @param value
* @throws GraphQLRequestExecutionException
*/
private void appendStringContentForGraphqlQueryFromValueItem(StringBuilder sb, Object value) {
protected void appendStringContentForGraphqlQueryFromValueItem(StringBuilder sb, Object value) {
if (value instanceof Map) {
appendStringContentForGraphqlQueryFromMap(sb, (Map<?, ?>) value);
} else if (value instanceof List) {
Expand All @@ -1046,7 +1048,7 @@ private void appendStringContentForGraphqlQueryFromValueItem(StringBuilder sb, O
* @see <a href="https://www.json.org/">json.org section on strings</a>
* @return escaped string
*/
private String getStringValue(String str) {
protected String getStringValue(String str) {
String r = "\"" + StringEscapeUtils.escapeJson(str) + "\"";
return r;
}
Expand All @@ -1071,7 +1073,7 @@ private String getStringValue(String str) {
* @throws NullPointerException
* If list is null
*/
private String getStringContentForAListValue(boolean writingGraphQLVariables, Object list, int listDepth,
protected String getStringContentForAListValue(boolean writingGraphQLVariables, Object list, int listDepth,
String graphQLTypeNameParam, GraphQLScalarType graphQLScalarTypeParam, boolean graphQLVariable)
throws GraphQLRequestExecutionException {
StringBuilder result = new StringBuilder("[");
Expand Down Expand Up @@ -1114,7 +1116,7 @@ private String getStringContentForAListValue(boolean writingGraphQLVariables, Ob
* @return The String that represents this object, according to GraphQL standard representation, as expected in the
* query to be sent to the server
*/
private String getStringContentForAnInputTypeValue(boolean writingGraphQLVariables, Object object, int listDepth,
protected String getStringContentForAnInputTypeValue(boolean writingGraphQLVariables, Object object, int listDepth,
boolean graphQLVariable) throws GraphQLRequestExecutionException {
StringBuilder result = new StringBuilder("{");
String separator = "";
Expand Down