89
89
import org .apache .commons .httpclient .methods .PostMethod ;
90
90
import org .apache .commons .httpclient .methods .StringRequestEntity ;
91
91
import org .apache .commons .httpclient .params .HttpClientParams ;
92
+ import org .apache .commons .lang .StringEscapeUtils ;
92
93
import org .apache .commons .lang .StringUtils ;
93
94
import org .apache .commons .lang .time .StopWatch ;
94
95
import org .jetbrains .annotations .NotNull ;
@@ -406,10 +407,9 @@ public void executeGraphQL(Editor editor, VirtualFile virtualFile) {
406
407
final JSGraphQLEndpoint selectedEndpoint = endpointsModel .getSelectedItem ();
407
408
if (selectedEndpoint != null && selectedEndpoint .url != null ) {
408
409
final JSGraphQLQueryContext context = JSGraphQLQueryContextHighlightVisitor .getQueryContextBufferAndHighlightUnused (editor );
409
- final Map <String , Object > requestData = Maps .newLinkedHashMap ();
410
- requestData .put ("query" , context .query );
410
+ String variables ;
411
411
try {
412
- requestData . put ( " variables" , getQueryVariables (editor ) );
412
+ variables = getQueryVariables (editor );
413
413
} catch (JsonSyntaxException jse ) {
414
414
Editor errorEditor = editor .getUserData (GRAPH_QL_VARIABLES_EDITOR );
415
415
String errorMessage = jse .getMessage ();
@@ -434,7 +434,7 @@ public void executeGraphQL(Editor editor, VirtualFile virtualFile) {
434
434
hintManager .showEditorHint (lightweightHint , editor , hintPosition , 0 , 10000 , false , HintManager .UNDER );
435
435
return ;
436
436
}
437
- final String requestJson = new Gson (). toJson ( requestData ) ;
437
+ final String requestJson = "{ \" query \" : \" " + StringEscapeUtils . escapeJavaScript ( context . query )+ " \" , \" variables \" :" + variables + "}" ;
438
438
final HttpClient httpClient = new HttpClient (new HttpClientParams ());
439
439
try {
440
440
final PostMethod method = new PostMethod (selectedEndpoint .url );
@@ -527,11 +527,14 @@ private Integer getErrorCount(String responseJson) {
527
527
return null ;
528
528
}
529
529
530
- private Object getQueryVariables (Editor editor ) {
530
+ private String getQueryVariables (Editor editor ) {
531
531
final Editor variablesEditor = editor .getUserData (GRAPH_QL_VARIABLES_EDITOR );
532
532
if (variablesEditor != null ) {
533
533
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
+ }
535
538
}
536
539
return null ;
537
540
}
0 commit comments