Skip to content

Commit 5b5fba3

Browse files
committed
Send the variables editor text as-is since Gson always deserializes a JSON number as a Double (This turns a variable value of 1 into 1.0, making the value incompatible with the Int schema type) (#86)
1 parent 3af01a7 commit 5b5fba3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/com/intellij/lang/jsgraphql/ide/project/JSGraphQLLanguageUIProjectService.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import org.apache.commons.httpclient.methods.PostMethod;
9090
import org.apache.commons.httpclient.methods.StringRequestEntity;
9191
import org.apache.commons.httpclient.params.HttpClientParams;
92+
import org.apache.commons.lang.StringEscapeUtils;
9293
import org.apache.commons.lang.StringUtils;
9394
import org.apache.commons.lang.time.StopWatch;
9495
import org.jetbrains.annotations.NotNull;
@@ -406,10 +407,9 @@ public void executeGraphQL(Editor editor, VirtualFile virtualFile) {
406407
final JSGraphQLEndpoint selectedEndpoint = endpointsModel.getSelectedItem();
407408
if(selectedEndpoint != null && selectedEndpoint.url != null) {
408409
final JSGraphQLQueryContext context = JSGraphQLQueryContextHighlightVisitor.getQueryContextBufferAndHighlightUnused(editor);
409-
final Map<String, Object> requestData = Maps.newLinkedHashMap();
410-
requestData.put("query", context.query);
410+
String variables;
411411
try {
412-
requestData.put("variables", getQueryVariables(editor));
412+
variables = getQueryVariables(editor);
413413
} catch (JsonSyntaxException jse) {
414414
Editor errorEditor = editor.getUserData(GRAPH_QL_VARIABLES_EDITOR);
415415
String errorMessage = jse.getMessage();
@@ -434,7 +434,7 @@ public void executeGraphQL(Editor editor, VirtualFile virtualFile) {
434434
hintManager.showEditorHint(lightweightHint, editor, hintPosition, 0, 10000, false, HintManager.UNDER);
435435
return;
436436
}
437-
final String requestJson = new Gson().toJson(requestData);
437+
final String requestJson = "{\"query\":\""+ StringEscapeUtils.escapeJavaScript(context.query)+"\", \"variables\":" + variables + "}";
438438
final HttpClient httpClient = new HttpClient(new HttpClientParams());
439439
try {
440440
final PostMethod method = new PostMethod(selectedEndpoint.url);
@@ -527,11 +527,14 @@ private Integer getErrorCount(String responseJson) {
527527
return null;
528528
}
529529

530-
private Object getQueryVariables(Editor editor) {
530+
private String getQueryVariables(Editor editor) {
531531
final Editor variablesEditor = editor.getUserData(GRAPH_QL_VARIABLES_EDITOR);
532532
if (variablesEditor != null) {
533533
final String variables = variablesEditor.getDocument().getText();
534-
return new Gson().fromJson(variables, Map.class);
534+
if(!StringUtils.isBlank(variables)) {
535+
new Gson().fromJson(variables, Map.class);
536+
return variables;
537+
}
535538
}
536539
return null;
537540
}

0 commit comments

Comments
 (0)