[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/graphql-mode 2371316a75 116/122: Merge pull request #42 fr
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/graphql-mode 2371316a75 116/122: Merge pull request #42 from adimit/headers-buffer |
Date: |
Sat, 29 Jan 2022 08:03:40 -0500 (EST) |
branch: elpa/graphql-mode
commit 2371316a750b807de941184d49ca19d277ecadcd
Merge: 9bed568ec8 3e27ae34cd
Author: David Vázquez Púa <davazp@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #42 from adimit/headers-buffer
Headers buffer
---
README.md | 13 ++++++++++++
graphql-mode.el | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+)
diff --git a/README.md b/README.md
index 452adcd1bd..7fe748a758 100644
--- a/README.md
+++ b/README.md
@@ -14,3 +14,16 @@ extension will be loaded with this mode.
You can optionally install `json-mode`, and it will be enabled in the
buffer that contains the response from a GraphQL service.
+
+## Querying Endpoints
+
+To send a query to a server, you will first need the
+[`request`](https://github.com/tkf/emacs-request) package. Then use
+`graphql-send-query` (`C-c C-c`) to send a query.
+
+If you have a `.graphqlconfig` file, you can select an endpoint configuration
+with `graphql-select-endpoint` (`C-c C-l`).
+
+To send additional headers for a request, `graphql-extra-headers` must be
+set. It is automatically set by `graphql-select-endpoint`, or you can edit its
+value using JSON with `graphql-edit-headers` (`C-c e h`).
diff --git a/graphql-mode.el b/graphql-mode.el
index 68f0364be2..9b7b846556 100644
--- a/graphql-mode.el
+++ b/graphql-mode.el
@@ -261,6 +261,7 @@ Please install it and try again."))
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") 'graphql-send-query)
(define-key map (kbd "C-c C-l") 'graphql-select-endpoint)
+ (define-key map (kbd "C-c e h") 'graphql-edit-headers)
map)
"Key binding for GraphQL mode.")
@@ -272,6 +273,9 @@ Please install it and try again."))
st)
"Syntax table for GraphQL mode.")
+(defvar-local graphql-edit-headers--parent-buffer nil)
+(put 'graphql-edit-headers--parent-buffer 'permanent-local t)
+
(defun graphql-indent-line ()
"Indent GraphQL schema language."
@@ -388,6 +392,63 @@ This is the function to be used for the hook
`completion-at-point-functions'."
(1 font-lock-variable-name-face)))
"Font Lock keywords.")
+;;; Edit headers functionality:
+
+(defun graphql-edit-headers ()
+ "Edit graphql request headers interactively in a dedicated buffer.
+
+Open a buffer to edit `graphql-extra-headers'. The contents of this
+buffer take precedence over the setting in `graphql-extra-headers'
+when sending a request."
+ (interactive)
+ (unless (equal major-mode 'graphql-mode)
+ (error "Not in graphql-mode, cannot edit headers"))
+ (let ((extra-headers-buffer-name
+ (concat "*Graphql Headers for " (buffer-name) "*"))
+ (parent-buffer (current-buffer)))
+ (pop-to-buffer extra-headers-buffer-name)
+ (setq-local graphql-edit-headers--parent-buffer parent-buffer)
+ (if (and (string-empty-p (buffer-string)) graphql-extra-headers)
+ (progn
+ (insert (json-encode graphql-extra-headers))
+ (json-pretty-print (point-min) (point-max))
+ (goto-char (point-min))))
+ (when (fboundp 'json-mode)
+ (json-mode))
+ (graphql-edit-headers-mode)))
+
+(defun graphql-edit-headers-buffer-p ()
+ "Non-nil when current buffer is a header editing buffer."
+ (bound-and-true-p graphql-edit-headers-mode))
+
+(defun graphql-edit-headers-accept ()
+ "Accept buffer contents and write to `graphql-extra-headers'."
+ (interactive)
+ (unless (graphql-edit-headers-buffer-p) (error "Not in a GraphQL headers
buffer"))
+ (let ((new-headers (json-read-from-string (buffer-string))))
+ (with-current-buffer graphql-edit-headers--parent-buffer
+ (setq-local graphql-extra-headers new-headers)))
+ (quit-window 'kill-buffer))
+
+(defun graphql-edit-headers-abort ()
+ "Kill current headers buffer and return to graphql file."
+ (interactive)
+ (unless (graphql-edit-headers-buffer-p) (error "Not in a GraphQL headers
buffer"))
+ (quit-window 'kill-buffer))
+
+(define-minor-mode graphql-edit-headers-mode
+ "Minor mode for editing graphql extra headers.
+\\<graphql-mode-map>
+This minor mode is turned on when you edit GraphQL headers
+interactively with `\\[graphql-edit-headers]'."
+ :lighter " GQL Hdr"
+ :keymap (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-c C-c") 'graphql-edit-headers-accept)
+ (define-key map (kbd "C-c C-k") 'graphql-edit-headers-abort)
+ map)
+ (setq header-line-format (substitute-command-keys "Edit GraphQL query
headers. Save with \
+`\\[graphql-edit-headers-accept]' or abort with
`\\[graphql-edit-headers-abort]'")))
+
;;;###autoload
(define-derived-mode graphql-mode prog-mode "GraphQL"
- [nongnu] elpa/graphql-mode 0b4152d485 051/122: Fix tests to use variables, (continued)
- [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, 2022/01/29
- [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 <=
- [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
- [nongnu] elpa/graphql-mode fe8d7e2db5 117/122: Add version attribute to package header, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 6308d80a2c 121/122: Update parameter regex to match graphql standard, ELPA Syncer, 2022/01/29