|
39 | 39 | import com.intellij.lang.jsgraphql.ide.endpoints.JSGraphQLEndpoint; |
40 | 40 | import com.intellij.lang.jsgraphql.ide.endpoints.JSGraphQLEndpointsModel; |
41 | 41 | import com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLErrorResult; |
42 | | -import com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLLanguageToolWindowManager; |
43 | 42 | import com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLErrorTreeViewPanel; |
| 43 | +import com.intellij.lang.jsgraphql.ide.project.toolwindow.JSGraphQLLanguageToolWindowManager; |
44 | 44 | import com.intellij.lang.jsgraphql.languageservice.JSGraphQLNodeLanguageServiceClient; |
45 | 45 | import com.intellij.lang.jsgraphql.languageservice.JSGraphQLNodeLanguageServiceInstance; |
46 | 46 | import com.intellij.lang.jsgraphql.psi.JSGraphQLFile; |
@@ -406,7 +406,21 @@ public void executeGraphQL(Editor editor, VirtualFile virtualFile) { |
406 | 406 | final JSGraphQLQueryContext context = JSGraphQLQueryContextHighlightVisitor.getQueryContextBufferAndHighlightUnused(editor); |
407 | 407 | final Map<String, Object> requestData = Maps.newLinkedHashMap(); |
408 | 408 | 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 | + } |
410 | 424 | final String requestJson = new Gson().toJson(requestData); |
411 | 425 | final HttpClient httpClient = new HttpClient(new HttpClientParams()); |
412 | 426 | try { |
@@ -500,13 +514,11 @@ private Integer getErrorCount(String responseJson) { |
500 | 514 | return null; |
501 | 515 | } |
502 | 516 |
|
503 | | - private String getQueryVariables(Editor editor) { |
| 517 | + private Object getQueryVariables(Editor editor) { |
504 | 518 | final Editor variablesEditor = editor.getUserData(GRAPH_QL_VARIABLES_EDITOR); |
505 | | - if(variablesEditor != null) { |
| 519 | + if (variablesEditor != null) { |
506 | 520 | final String variables = variablesEditor.getDocument().getText(); |
507 | | - if(StringUtils.isNotEmpty(variables)) { |
508 | | - return variables; |
509 | | - } |
| 521 | + return new Gson().fromJson(variables, Map.class); |
510 | 522 | } |
511 | 523 | return null; |
512 | 524 | } |
|
0 commit comments