8989import org .apache .commons .httpclient .methods .PostMethod ;
9090import org .apache .commons .httpclient .methods .StringRequestEntity ;
9191import org .apache .commons .httpclient .params .HttpClientParams ;
92+ import org .apache .commons .lang .StringEscapeUtils ;
9293import org .apache .commons .lang .StringUtils ;
9394import org .apache .commons .lang .time .StopWatch ;
9495import 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