[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/graphql-mode 3cbaa5ef35 041/122: Add multiple queries defi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/graphql-mode 3cbaa5ef35 041/122: Add multiple queries definition and variables support |
Date: |
Sat, 29 Jan 2022 08:03:31 -0500 (EST) |
branch: elpa/graphql-mode
commit 3cbaa5ef358159f024def417be47521c1251f2a4
Author: Tim Shiu <punshiu@fb.com>
Commit: Tim Shiu <punshiu@fb.com>
Add multiple queries definition and variables support
---
graphql-mode.el | 49 +++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 43 insertions(+), 6 deletions(-)
diff --git a/graphql-mode.el b/graphql-mode.el
index aa8879623c..a8e6c08e27 100644
--- a/graphql-mode.el
+++ b/graphql-mode.el
@@ -62,8 +62,11 @@
(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))))
+ (let* ((url-request-method "POST")
+ (query (url-encode-url query))
+ (operation (graphql-current-operation))
+ (variables (url-encode-url (graphql-current-variables)))
+ (url (format "%s?query=%s&operationName=%s&variables=%s" graphql-url
query operation variables)))
(with-current-buffer (url-retrieve-synchronously url t)
(goto-char (point-min))
(search-forward "\n\n")
@@ -86,6 +89,8 @@ response from the server."
(forward-line 1)))
(defun graphql-current-query ()
+ "find out the current query/mutation/subscription"
+ (interactive)
(let ((start
(save-excursion
(graphql-beginning-of-query)
@@ -96,12 +101,46 @@ response from the server."
(point))))
(buffer-substring-no-properties start end)))
+(defun graphql-current-operation ()
+ "get the name of the query operation"
+ (interactive)
+ (let* ((query
+ (save-excursion
+ (replace-regexp-in-string "^[ \t\n]*" "" (graphql-current-query))))
+ (tokens
+ (split-string query "[ \f\t\n\r\v]+"))
+ (first (nth 0 tokens)))
+
+ (if (string-equal first "{")
+ ""
+ (replace-regexp-in-string "[({:]+" "" (nth 1 tokens)))))
+
+(defun graphql-current-variables ()
+ "get the content of graphql variables"
+ (interactive)
+ (let ((variables
+ (save-excursion
+ (goto-char (point-max))
+ (search-backward-regexp "^variables" (point-min) t)
+ (search-forward-regexp "^variables" (point-max) t)
+ (point))))
+ (buffer-substring-no-properties variables (point-max))
+ ))
+
+(defun graphql-beginning-of-variables ()
+ "get the beginning point of graphql variables"
+ (interactive)
+ (save-excursion
+ (goto-char (point-max))
+ (search-backward-regexp "^variables" (point-min) t)
+ (beginning-of-line)
+ (point)))
(defun graphql-send-query ()
(interactive)
(let ((url (or graphql-url (read-string "GraphQL URL: " ))))
(let ((graphql-url url))
- (let* ((query (buffer-substring-no-properties (point-min) (point-max)))
+ (let* ((query (buffer-substring-no-properties (point-min)
(graphql-beginning-of-variables)))
(response (graphql--query query)))
(with-current-buffer-window
"*GraphQL*" 'display-buffer-pop-up-window nil
@@ -116,8 +155,6 @@ response from the server."
(setq graphql-url url)
nil))
-
-
(defvar graphql-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") 'graphql-send-query)
@@ -149,7 +186,7 @@ response from the server."
(defvar graphql-definition-regex
- (concat "\\(" (regexp-opt '("type" "input" "interface" "fragment" "query"
"enum")) "\\)"
+ (concat "\\(" (regexp-opt '("type" "input" "interface" "fragment" "query"
"mutation" "variables" "subscription" "enum")) "\\)"
"[[:space:]]+\\(\\_<.+?\\_>\\)"))
(defvar graphql-builtin-types
- [nongnu] elpa/graphql-mode 7482c1b100 025/122: Add basic commentary, (continued)
- [nongnu] elpa/graphql-mode 7482c1b100 025/122: Add basic commentary, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 36b1a4ed9f 070/122: Merge pull request #16 from emacsjanitors/no-request, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 4b0134a19a 050/122: forget docstring, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 5f2ee4b3b3 024/122: Add melpa badge, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 8e58196e21 023/122: Merge pull request #1 from syohex/fix-package, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 2ee89d4e05 080/122: Fix Error during redisplay, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 0b4152d485 051/122: Fix tests to use variables, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 74ee772a62 087/122: Merge pull request #26 from Malabarba/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode ebd6502c09 085/122: Merge pull request #25 from Malabarba/operation-bug, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode f1be68cea4 108/122: Add key binding for editing headers, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 3cbaa5ef35 041/122: Add multiple queries definition and variables support,
ELPA Syncer <=
- [nongnu] elpa/graphql-mode 4c942986fa 086/122: Also insert response headers in the buffer (with comment face), ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 6f6b303af4 084/122: Merge pull request #24 from Malabarba/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 301a218674 090/122: Enable json-mode for the output buffer., ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode fb84a08434 069/122: Make the dependency on request optional, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode e757919fe3 093/122: Merge pull request #30 from conao3/fix-warning, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 2371316a75 116/122: Merge pull request #42 from adimit/headers-buffer, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode c176b16a41 112/122: Fix header line documentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 942d3c739a 113/122: Fix typo in key binding, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 3e27ae34cd 115/122: Remember parent buffer & set g-e-h locally therein, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode d9d3bba569 088/122: added support for 'extend', 'scalar' and 'union' keywords, ELPA Syncer, 2022/01/29