private void runQuery()

in src/main/com/intellij/lang/jsgraphql/ui/GraphQLUIProjectService.java [417:506]


  private void runQuery(@NotNull Editor editor,
                        @NotNull VirtualFile virtualFile,
                        @NotNull GraphQLQueryContext context,
                        @NotNull String url,
                        @NotNull HttpUriRequest request,
                        @NotNull GraphQLConfigEndpoint endpoint) {
    try {
      GraphQLConfigSecurity sslConfig = GraphQLConfigSecurity.getSecurityConfig(endpoint.getConfig());
      try (final CloseableHttpClient httpClient = GraphQLQueryClient.getInstance(myProject).createHttpClient(url, sslConfig)) {
        editor.putUserData(GRAPH_QL_EDITOR_QUERYING, true);

        String responseJson;
        Header contentType;
        long start = System.currentTimeMillis();
        long end;
        try (final CloseableHttpResponse response = httpClient.execute(request)) {
          responseJson = StringUtil.notNullize(EntityUtils.toString(response.getEntity()));
          contentType = response.getFirstHeader("Content-Type");
        }
        finally {
          end = System.currentTimeMillis();
        }

        final boolean reformatJson = contentType != null && contentType.getValue() != null &&
                                     contentType.getValue().startsWith("application/json");
        final Integer errorCount = getErrorCount(responseJson);
        ApplicationManager.getApplication().invokeLater(() -> {
          TextEditor queryResultEditor = GraphQLToolWindow.getQueryResultEditor(myProject);
          if (queryResultEditor == null) {
            return;
          }

          updateQueryResultEditor(responseJson, queryResultEditor, reformatJson);
          String queryResultText = GraphQLBundle.message(
            "graphql.query.result.statistics",
            virtualFile.getName(),
            end - start,
            bytesToDisplayString(responseJson.length())
          );

          if (errorCount != null && errorCount > 0) {
            queryResultText += GraphQLBundle.message(
              "graphql.query.result.statistics.error",
              errorCount,
              errorCount > 1
              ? GraphQLBundle.message("graphql.query.result.statistics.multiple.errors")
              : GraphQLBundle.message("graphql.query.result.statistics.single.error")
            );

            if (context.onError != null) {
              context.onError.run();
            }
          }

          GraphQLToolWindow.GraphQLQueryResultHeaderComponent queryResultHeader =
            GraphQLToolWindow.getQueryResultHeader(queryResultEditor);
          if (queryResultHeader == null) return;

          JBLabel queryResultLabel = queryResultHeader.getResultLabel();
          @NlsSafe String resultTextString = queryResultText;
          queryResultLabel.setText(resultTextString);
          queryResultLabel.putClientProperty(GraphQLToolWindow.FILE_URL_PROPERTY, virtualFile.getUrl());
          if (!queryResultLabel.isVisible()) {
            queryResultLabel.setVisible(true);
          }

          JBLabel queryStatusLabel = queryResultHeader.getStatusLabel();
          queryStatusLabel.setVisible(errorCount != null);
          if (queryStatusLabel.isVisible() && errorCount != null) {
            if (errorCount == 0) {
              queryStatusLabel.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 0));
              queryStatusLabel.setIcon(AllIcons.General.InspectionsOK);
            }
            else {
              queryStatusLabel.setBorder(BorderFactory.createEmptyBorder(2, 12, 0, 4));
              queryStatusLabel.setIcon(AllIcons.Ide.ErrorPoint);
            }
          }

          GraphQLToolWindow.showQueryResultEditor(myProject);
        });
      }
      finally {
        editor.putUserData(GRAPH_QL_EDITOR_QUERYING, null);
      }
    }
    catch (IOException | GeneralSecurityException e) {
      GraphQLNotificationUtil.handleGenericRequestError(myProject, url, e, NotificationType.WARNING);
    }
  }