[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/graphql-mode 319dfd97d7 011/122: Define graphql-send-query
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/graphql-mode 319dfd97d7 011/122: Define graphql-send-query |
Date: |
Sat, 29 Jan 2022 08:03:29 -0500 (EST) |
branch: elpa/graphql-mode
commit 319dfd97d789f58b00e9a88ee2121e363c7a0012
Author: David Vazquez Pua <davazp@gmail.com>
Commit: David Vazquez Pua <davazp@gmail.com>
Define graphql-send-query
Send the current query to the configured GraphQL URL and pretty-print
the response.
---
graphql.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/graphql.el b/graphql.el
index 93e71f8281..d9b920e815 100644
--- a/graphql.el
+++ b/graphql.el
@@ -25,6 +25,68 @@
;;; Code:
(require 'newcomment)
+(require 'json)
+(require 'url)
+
+(defvar graphql-url
+ "http://graphql-swapi.parseapp.com")
+
+
+(defun graphql--query (query)
+ "Send QUERY to the server at `graphql-url' and return the
+response from the server."
+ (let ((url-request-method "POST")
+ (url (format "%s/?query=%s" graphql-url (url-encode-url query))))
+ (with-current-buffer (url-retrieve-synchronously url t)
+ (goto-char (point-min))
+ (search-forward "\n\n")
+ (buffer-substring (point) (point-max)))))
+
+(defun graphql-beginning-of-query ()
+ "Move the point to the beginning of the current query."
+ (interactive)
+ (while (and (> (point) (point-min))
+ (or (> (current-indentation) 0)
+ (> (car (syntax-ppss)) 0)))
+ (forward-line -1)))
+
+(defun graphql-end-of-query ()
+ "Move the point to the end of the current query."
+ (interactive)
+ (while (and (< (point) (point-max))
+ (or (> (current-indentation) 0)
+ (> (car (syntax-ppss)) 0)))
+ (forward-line 1)))
+
+(defun graphql-current-query ()
+ (let ((start
+ (save-excursion
+ (graphql-beginning-of-query)
+ (point)))
+ (end
+ (save-excursion
+ (graphql-end-of-query)
+ (point))))
+ (buffer-substring-no-properties start end)))
+
+
+(defun graphql-send-query ()
+ (interactive)
+ (let* ((query (graphql-current-query))
+ (response (graphql--query query)))
+ (with-current-buffer-window
+ "*GraphQL*" 'display-buffer-pop-up-window nil
+ (erase-buffer)
+ (json-mode)
+ (insert response)
+ (json-pretty-print-buffer))))
+
+
+
+(defvar graphql-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-c C-c") 'graphql-send-query)
+ map))
(defvar graphql-mode-syntax-table
(let ((st (make-syntax-table)))
- [nongnu] branch elpa/graphql-mode created (now 9740e4027b), ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 14bbd1917e 032/122: Update copyright notice, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 12ab2d0eb5 060/122: Merge pull request #13 from timoweave/next, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode de4b2e8117 039/122: Remember graphql-url value only if the query is successful, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode ead2f85e12 047/122: add error handling, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 22cb9d4594 071/122: Support customizing the headers sent with the request, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 1210279ff4 063/122: Add keywords only completion, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 4bb868832f 078/122: Avoid double-encoding variables in JSON, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode a665c9514a 054/122: fix docstring, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 4c87cdab57 018/122: Fix: make the graphql-url buffer-local before the mode is enabled, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 319dfd97d7 011/122: Define graphql-send-query,
ELPA Syncer <=
- [nongnu] elpa/graphql-mode eed3c6ca1c 036/122: Create sample GraphQL server, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 404aa31258 104/122: Save json to graphql-edit-headers, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 16c3d63521 002/122: First commit, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 5bd8b6273e 003/122: fontify more graphql constructions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode bf0412def0 006/122: Better fontification of type [implements X]?, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 1f3bd34b18 064/122: Merge pull request #14 from davazp/next, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode b1aea740ac 052/122: Some fixes to the support of variables, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode e254c7405d 037/122: graphql-send-query uses the whole buffer, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 03312c9f1c 045/122: add variables file support, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 09669d4343 089/122: Merge pull request #28 from charles-boyd/enhancement/add-missing-graphql-keywords, ELPA Syncer, 2022/01/29