Skip to content

Commit 6e3d0b8

Browse files
Merge pull request #65 from zvorygin/master
Pass "variables" through POST method as JSON, not string.
2 parents a0e56c0 + 1d350e1 commit 6e3d0b8

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
import com.intellij.lang.jsgraphql.ide.endpoints.JSGraphQLEndpoint;
4040
import com.intellij.lang.jsgraphql.ide.endpoints.JSGraphQLEndpointsModel;
4141
import com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLErrorResult;
42-
import com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLLanguageToolWindowManager;
4342
import com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLErrorTreeViewPanel;
43+
import com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLLanguageToolWindowManager;
4444
import com.intellij.lang.jsgraphql.languageservice.JSGraphQLNodeLanguageServiceClient;
4545
import com.intellij.lang.jsgraphql.languageservice.JSGraphQLNodeLanguageServiceInstance;
4646
import com.intellij.lang.jsgraphql.psi.JSGraphQLFile;
@@ -406,7 +406,21 @@ public void executeGraphQL(Editor editor, VirtualFile virtualFile) {
406406
final JSGraphQLQueryContext context = JSGraphQLQueryContextHighlightVisitor.getQueryContextBufferAndHighlightUnused(editor);
407407
final Map<String, Object> requestData = Maps.newLinkedHashMap();
408408
requestData.put("query", context.query);
409-
requestData.put("variables", getQueryVariables(editor));
409+
try {
410+
requestData.put("variables", getQueryVariables(editor));
411+
} catch (JsonSyntaxException jse) {
412+
if (myToolWindowManagerInitialized) {
413+
myToolWindowManager.logCurrentErrors(ContainerUtil.immutableList(
414+
new JSGraphQLErrorResult(
415+
"Failed to parse variables as JSON: " + jse.getMessage(),
416+
virtualFile.getPath(),
417+
"Error",
418+
0,
419+
0))
420+
, true);
421+
}
422+
return;
423+
}
410424
final String requestJson = new Gson().toJson(requestData);
411425
final HttpClient httpClient = new HttpClient(new HttpClientParams());
412426
try {
@@ -500,13 +514,11 @@ private Integer getErrorCount(String responseJson) {
500514
return null;
501515
}
502516

503-
private String getQueryVariables(Editor editor) {
517+
private Object getQueryVariables(Editor editor) {
504518
final Editor variablesEditor = editor.getUserData(GRAPH_QL_VARIABLES_EDITOR);
505-
if(variablesEditor != null) {
519+
if (variablesEditor != null) {
506520
final String variables = variablesEditor.getDocument().getText();
507-
if(StringUtils.isNotEmpty(variables)) {
508-
return variables;
509-
}
521+
return new Gson().fromJson(variables, Map.class);
510522
}
511523
return null;
512524
}

0 commit comments

Comments
 (0)