branch: elpa/graphql-mode
commit de4b2e8117f26e5ad98387f715ce4c6cffa40c73
Author: David Vazquez Pua <[email protected]>
Commit: David Vazquez Pua <[email protected]>
Remember graphql-url value only if the query is successful
This fixes #6
---
graphql-mode.el | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/graphql-mode.el b/graphql-mode.el
index cc14d75a6f..0dd61afdb7 100644
--- a/graphql-mode.el
+++ b/graphql-mode.el
@@ -99,17 +99,22 @@ response from the server."
(defun graphql-send-query ()
(interactive)
- (unless graphql-url
- (setq graphql-url (read-string "GraphQL URL: " )))
- (let* ((query (buffer-substring-no-properties (point-min) (point-max)))
- (response (graphql--query query)))
- (with-current-buffer-window
- "*GraphQL*" 'display-buffer-pop-up-window nil
- (erase-buffer)
- (when (fboundp 'json-mode)
- (json-mode))
- (insert response)
- (json-pretty-print-buffer))))
+ (let ((url (or graphql-url (read-string "GraphQL URL: " ))))
+ (let ((graphql-url url))
+ (let* ((query (buffer-substring-no-properties (point-min) (point-max)))
+ (response (graphql--query query)))
+ (with-current-buffer-window
+ "*GraphQL*" 'display-buffer-pop-up-window nil
+ (erase-buffer)
+ (when (fboundp 'json-mode)
+ (json-mode))
+ (insert response)
+ (json-pretty-print-buffer))))
+ ;; If the query was successful, then save the value of graphql-url
+ ;; in the current buffer (instead of the introduced local
+ ;; binding).
+ (setq graphql-url url)
+ nil))